2010-07-26 75 views
0

我正在摔跤这个问题。 我需要我的应用程序的肖像视图和风景视图。现在,当我创建2个按钮来显示纵向视图和横向视图(由shouldAutorotateToInterfaceOrientation强制)时,它们显示得很好。但是当我从imagepicker的结果代码中调用视图时,portraitview可以正常工作,但横向视图会像这样返回。 http://bit.ly/bfbobciPhone视图显示错误的方向

所以,只要说清楚:nob已经转动90度,imageviewcontrol只显示一半(右边的部分是屏幕外)...但iPhone并未强制进入横向模式...

有人可以请解释我这里发生了什么事情或我如何实现这一目标!欢迎任何帮助!

这就是我使用imagepickercontroller结果代码调用视图的方式。

` - (无效)imagePickerController:(的UIImagePickerController *)vcImagePicker didFinishPickingMediaWithInfo:(的NSDictionary *)信息{ 的NSLog(@ “的照片拍摄/选择,现在我们需要决定哪个视图来呈现”);

[vcImagePicker dismissModalViewControllerAnimated:YES]; 

UIImage *chosenPicture = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

if (chosenPicture.size.width > chosenPicture.size.height) { 
    NSLog(@"pic is in landscape"); 

    EditLandscapeScreen *vcEditLandscapeScreen = [[EditLandscapeScreen alloc] initWithNibName:@"EditLandscapeScreen" bundle:nil]; 
    vcEditLandscapeScreen.ChosenImage = chosenPicture; 
    [self.view addSubview:vcEditLandscapeScreen.view]; 
    [vcEditLandscapeScreen release]; 
} 
else { 
    NSLog(@"pic is in portrait"); 

    EditPortraitScreen *vcEditPortraitScreen = [[EditPortraitScreen alloc] initWithNibName:@"EditPortraitScreen" bundle:nil]; 
    vcEditPortraitScreen.ChosenImage = chosenPicture; 
    [self.view addSubview:vcEditPortraitScreen.view]; 
    [vcEditPortraitScreen release]; 
} 

}`

回答

1

如果添加一个子视图,你必须让你的子视图自己的方向变化的图。 willRotateToInterfaceOrientation只有将调用第一个视图控制器,所以如果你子视图添加到视图控制器这可能是你可以接受的方式:

在你的ViewController

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    for (int i = 0; i < [self.viewControllers count]; i++) { 
     [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    } 
} 

在你子视图的ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [self adjustViewsForOrientation:self.interfaceOrientation]; 
} 

    - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
     if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
      NSLog(@"Subview Landscape"); 
      //Do Your Landscape Changes here 
     } 
     else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
      NSLog(@"Subview Portrait"); 
      //Do Your Portrait Changes here 
     } 
    } 

这可能会让你走向正确的方向。

+0

我得到你要去的地方,但我想强制在子视图上的风景,而不仅仅是提供景观的可能性。 我强制这个使用'shouldAutorotateToInterfaceOrientation'并且左右为landscapemodes返回YES,但是当我调用子视图时,这个'强制'事情不起作用... 对此的任何想法?不管怎么说,还是要谢谢你! – Martijn 2010-07-28 08:44:05