如何旋转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;
    }    
}

但随后的横向 - 查看出现在所有标签。 (当此代码被加载一次)。 任何想法?

有帮助吗?

解决方案 3

您的意见坦克! 我发现一种解决方法:

//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];
    }
}

其他提示

这是怎么回事是您的视图控制器接收每当旋转的变化,不管是不是正在显示它的UIDeviceOrientationDidChangeNotification通知。代替尝试使用旨在用于响应转动UIViewController的内置方法。

http://tinyurl.com/ycb8of2

这是从苹果公司的文档(视图控制器编程指南):

  

标签栏控制器和视图旋转

     

标签栏控制器支持的肖像   默认情况下,定向和不   旋转到横向   除非所有的根视图的   控制器支持这样的   取向。当设备方向   发生变化,标签栏控制器   查询其视图控制器的阵列。   如果其中任何一项不支持   方向,标签栏   控制器不改变其   取向。

所以,我不知道该标签栏控制器的设计只需旋转的单一视图。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top