我正在用iOS6做我的项目。我只有一个now.ON的UIViewController,我有一个UIScrollView。我有几个控件(文本字段,按钮,自定义view..etc).So我为肖像模式构建的项目。现在我想移动它,使其同时适合风景和肖像。为此,我有以下代码
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
self.scrollView.contentMode = UIViewContentModeTopRight;
self.scrollView.scrollEnabled = YES;
NSLog(@"the end point is %f",self.currentCGRectLocation.origin.y);
CGPoint scrollPoint = CGPointMake(0.0, (self.currentCGRectLocation.origin.y/500)*400);
[self.scrollView setContentOffset:scrollPoint animated:YES];
CGFloat scrollViewHeight = 0.0f;
for (UIView *view in self.scrollView.subviews)
{
scrollViewHeight += view.frame.size.height;
}
CGSize newSize = CGSizeMake(100,scrollViewHeight);
[self.scrollView setContentSize:newSize];
self.view.userInteractionEnabled =YES;
self.scrollView.userInteractionEnabled = YES;
}在我的viewDidLoad中
- (void)viewDidLoad
{
[self.scrollView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
}在我的AppDelegate.m文件中
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}我的问题是,我把它从纵向移动到横向,然后所有的控件都完美地对齐,除了滚动视图。模拟器在纵向模式下的宽度为900,在横向模式下为1024,所以我的滚动视图即使在横向模式下也可以滚动到900的宽度。虽然我可以很容易地上下移动,但它就像卡在那里一样。我附上了一个模型。滚动视图位于肖像的末尾(900),几乎2/3的滚动视图位于横向(900)。模型在这里:http://dl.dropbox.com/u/40597849/mockup3.png。如果您需要更多信息,请访问ask.Thanks。
编辑:同样在UIScrollView的MainStoryboard上,我已经取消选中了“使用自动布局”复选框。如果我选中它,当我从纵向移动到横向时,我会在最后(如我所希望的)看到滚动视图。但是当我再次从横向移动到纵向时,屏幕冻结了。我不能上下移动。
发布于 2013-01-09 04:23:42
这两个方法是在ViewController中添加的,我想将其从纵向移动到横向。我仍然保持我的“使用自动布局”复选框未选中滚动视图。
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
CGRect rect = self.view.frame;
rect.size.width = self.view.frame.size.width+245;
rect.size.height = self.view.frame.size.height+245;
self.scrollView.frame = rect;
}}
它被添加到AppDelegate.m文件中
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}这对我来说很管用。希望能有所帮助。
https://stackoverflow.com/questions/14206136
复制相似问题