2010-07-26 73 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