重绘scrollView及其内容以实现横向
我有一个简单的页面,顶部有导航栏,底部有选项卡栏,滚动视图填充之间的空间。滚动视图包含标签和图像以及不可滚动的文本视图,该文本视图动态填充文本并适当调整大小。我一直在尝试通过使用使其在横向工作:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(@"called");
navBar.frame = CGRectMake(0, 0, 480, 32);
sview.frame = CGRectMake(0, 32, 480, 240);
}
else {
navBar.frame = CGRectMake(0, 0, 320, 44);
sview.frame = CGRectMake(0, 44, 320, 372);
}
}
这让我非常接近,因为导航栏和滚动视图正确调整大小并且滚动得很好,但滚动视图中的内容位于左侧。如何重绘内容以在滚动视图中正确排列?
I have a simple page with a nav bar at the top, tab bar at the bottom, and a scrollview filling the space between. The scrollview contains a label and image and a non-scrollable textview that gets dynamically filled with text and sized appropriately. I've been trying to make it work in landscape by using:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(@"called");
navBar.frame = CGRectMake(0, 0, 480, 32);
sview.frame = CGRectMake(0, 32, 480, 240);
}
else {
navBar.frame = CGRectMake(0, 0, 320, 44);
sview.frame = CGRectMake(0, 44, 320, 372);
}
}
This gets me very close as the nav bar and scrollview resize correctly and it scrolls nicely, but the content within the scrollview is off to the left. How do I redraw the contents to line up correctly within the scrollview?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尼克在评论中提供了正确答案。我只需更改滚动视图中项目的自动调整大小蒙版。我做了:
对于 viewDidLoad 方法中的每个项目。
Nick provided the correct answer in his comment. I just had to change the autoresizemasks of the items in the scrollview. I did:
for each item in the viewDidLoad method.