我正在尝试检测用户获得的手机大小,并将滚动视图长度设置为合适的大小。例如,如果用户使用的是iPhone加上滚动长度,那么如果用户使用的是iPhone 5,则滚动长度应该更短
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (!pageControlBeingUsed) {
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scroll2.frame.size.width;
int page = floor((self.scroll2.contentOffset.x - pageWidth / 3) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
if([UIScreen mainScreen].bounds.size.height == 667.0){
self.scroll2.contentSize = CGSizeMake(300, 100);
// iPhone retina-4.7 inch(iPhone 6)
}
else if([UIScreen mainScreen].bounds.size.height == 568.0){
self.scroll2.contentSize = CGSizeMake(300, 5500);
// iPhone retina-4 inch(iPhone 5 or 5s)
}
else{
// iPhone retina-5 inch inch(iPhone Plus)
}
}
}发布于 2017-09-28 17:19:40
您可以实现这种自动layout.Just,将所有内容放在一个UIView中,然后将此UIView添加到滚动视图中,并带有五个约束
顶层
在此之后,您可以实现无需检查屏幕大小的解决方案。如果您是自动布局新手,请阅读本教程https://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/
https://stackoverflow.com/questions/46465199
复制相似问题