我已经为iPhone创建了一个应用程序,它完全适合iPhone 5 / 5S / 5C屏幕。但是,我试图在iPhone 4 / 4S(较小的屏幕)上使用ScrollView。
我的视图嵌入在导航栏控制器中,也位于标签栏控制器中。我的Scroll View位于两者之间的空间,当它在iPhone 5 / 5S / 5C中时,我不希望它滚动,因为它已经是完美的尺寸。这部分工作正常。
然而,当我在模拟器上的较小屏幕尺寸上测试时,我希望它能够滚动,但它根本不滚动。
我的滚动视图有一个IBOutlet,我在.m文件中使用以下代码行来设置滚动视图。
if (self.view.bounds.size.height == 568)
{
[_Scroller setContentSize:CGSizeMake(320, 1500)];
_Scroller.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height);
}
else
{
[_Scroller setContentSize:CGSizeMake(320, 80)];
_Scroller.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height);
}
_Scroller.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
[_Scroller setScrollEnabled:YES];
我还在视图控制器中调整了Scroll View Insets未选中,因为它在滚动视图的顶部不断添加恼人的间隙。
任何人都可以帮助我解决我的错误吗?这让我很生气!任何帮助都会很棒。我也是iOS开发的新手。
谢谢大家!
编辑:
我已将if语句更改为此但仍然无效:
if (self.view.bounds.size.height == 568)
{
[_Scroller setContentSize:CGSizeMake(320, 1500)];
_Scroller.frame = CGRectMake(-4, 64, 329, self.view.bounds.size.height);
}
else
{
[_Scroller setContentSize:CGSizeMake(320, 2000)];
_Scroller.frame = CGRectMake(-4, 64, 329, self.view.bounds.size.height);
}
_Scroller.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
[_Scroller setScrollEnabled:YES];
答案 0 :(得分:4)
像这样使用:
if ([[UIScreen mainScreen] bounds].size.height >= 568) //iphone 5/5c/5s/6/6 plus
{
//making ContentSize and frame's height same as not need of scrolling
//make changes in height if necessary
[_Scroller setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height-64)];
//make changes in height if necessary
_Scroller.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64);
}
else //iphone 4/4s
{
//making ContentSize greater than frame's height as we need scrolling
//make changes in height if necessary
[_Scroller setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height+64)];
if([[UIDevice currentDevice].systemVersion hasPrefix:@"7"]) //iOS 7.0 >
{
//made changes in y as status bar height is counted
_Scroller.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64);
}
else //iOS 6.1 <
{
//made changes in y as status bar height not counted
_Scroller.frame = CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height-64);
}
}