如何解决滚动视图随着更改方向而改变
| 我正在创建一个应用程序,在其中我使用了scrollview和insdie scrollview我使用了imageview来显示图像。但是当我将模拟器的方向更改为左/右横向时,随着方向的增加,imageview和scrollview的位置向左移动,同时重复相同的过程滚动观看和图像观看消失的阶段到来。我在视图中使用了两个视图,一个用于纵向视图,另一个用于横向视图。我必须显示差异。用于人像模式和横向模式的图像,因此任何人都可以帮助我..谢谢。这里有一些示例代码。- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation==UIInterfaceOrientationPortrait ||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
} else if(interfaceOrientation==UIInterfaceOrientationLandscapeLeft ||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
return YES;
}
return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation==UIInterfaceOrientationPortrait || orientation==UIInterfaceOrientationPortraitUpsideDown)
{CGRect frame=CGRectMake(0,45,320,480);
[sample_scroll_view setFrame:frame];
sample_scroll_view.contentSize = CGSizeMake(2560,275);
sample_scroll_view.pagingEnabled=YES;
sample_scroll_view.autoresizingMask =
( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
sample_scroll_view.autoresizesSubviews = YES;
}
else if (orientation==UIInterfaceOrientationLandscapeLeft || orientation==UIInterfaceOrientationLandscapeRight)
{
CGRect frame=CGRectMake(0,480,275);
[scroll_view2 setFrame:frame];
scroll_view2.contentSize = CGSizeMake(3140,275);
scroll_view2.maximumZoomScale = 4.0;
scroll_view2.minimumZoomScale = 0.75;
scroll_view2.bounces = NO;
scroll_view2.pagingEnabled=YES;
sample_scroll_view.autoresizingMask =
( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
sample_scroll_view.autoresizesSubviews = YES;
}
}
解决方法
您可以在xib文件的“视图”标签下,以自动调整大小模式进行一些设置。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。