我的任务是允许滚动风景。该设计是为肖像设计的。我想出了一个想法,将 ScrollView 添加到组件中,或者在 Interface Builder 的“嵌入滚动视图”中。我预计它会起作用,但没有。我正在使用Xcode 4.4,iOS 5.1,(office 项目也需要支持 4.2),但问题是一样的。
在 Stack Overflow 问题 iPhone SDK: UIScrollView does not scroll 中有一行解决了一个问题。
其他尝试在 Stack Overflow 问题中iOS - UIScrollView is not working (it doesn't scroll at all - the image stays fixed),这对我有帮助,结合其他,所以这是我的纵向可滚动横向代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromOrientation
{
if( UIInterfaceOrientationIsPortrait( [[UIApplication sharedApplication] statusBarOrientation] ) ){
scrollView.contentSize = portaitScrollSize;
}
else{//statusbar is Landscape
scrollView.contentSize = landscapeScrollSize;
}
}
在 Interface Builder 中绑定到 iVar 视图的滚动视图。 portaitScrollSize 和 landscapeScrollSize 是私有变量。它们被初始化并且不会改变。
在my.h 文件中:
IBOutlet UIScrollView *scrollView;
在my.m 文件中:
CGSize portaitScrollSize, landscapeScrollSize;
...
portaitScrollSize = CGSizeMake(320,440);
landscapeScrollSize = CGSizeMake(480,480);
我希望它能帮助某人在肖像设计中添加旋转+滚动功能。
不要忘记在顶部组件上允许纵向+横向:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return TRUE;
}