0

旋转 iphone 时如何更改视图(更改笔尖)。但它应该只发生在一个标签中!我试过了:

    - (void)viewDidLoad {
 LandscapeViewController *viewController = [[LandscapeViewController alloc]
             initWithNibName:@"LandscapeView" bundle:nil];
 self.landscapeViewController = viewController;
 [viewController release];

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
             name:UIDeviceOrientationDidChangeNotification object:nil]; }

- (void)orientationChanged:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
 {
        [self presentModalViewController:self.landscapeViewController animated:YES];
        isShowingLandscapeView = YES;
    }
 else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
 {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }    
}

但随后横向视图出现在所有选项卡中。(当此代码加载一次时)。任何的想法?

4

3 回答 3

0

发生的事情是您的视图控制器UIDeviceOrientationDidChangeNotification在旋转发生变化时收到通知,无论它是否正在显示。UIViewController而是尝试使用用于响应旋转的内置方法。

http://tinyurl.com/ycb8of2

于 2010-02-08T19:54:36.500 回答
0

这是来自 Apple 的文档(查看控制器编程指南):

标签栏控制器和视图旋转

标签栏控制器默认支持纵向,除非所有根视图控制器都支持这样的方向,否则不会旋转到横向。当设备方向发生变化时,标签栏控制器会查询其视图控制器数组。如果其中任何一个不支持方向,则标签栏控制器不会更改其方向。

所以,我不确定标签栏控制器是否设计为仅针对单个视图进行旋转。

于 2010-02-12T06:17:39.030 回答
0

坦克为您的意见!我找到了解决方法:

//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    }   
}

//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
    }
}
于 2010-02-12T11:09:53.263 回答