iPhone开发中,关于视图跳转的总结

iPhone开发中从一个视图跳到另一个视图有三种方法:
1、self.view addSubView:view 、self.window addSubView,需要注意的是,这个方法只是把页面加在当前页面。此时在用self.navigationControler.pushViewController和 pushViewController 是不行的。要想使用pushViewController和popViewController进行视图间的切换,就必须要求当前视图是个NavigationController。
2、就是使用self.navigationControler pushViewController和popViewController来进行视图切换的,pushViewController是进入到下一个视图,popViewController是返回到上一视图。
3、没有NavigationController导航栏的话,使用self.presentViewController和self.dismissModalViewController。具体是使用可以从文档中详细了解。
4、要想使用pushViewController和pushViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的。这里提供一个简单的方法让该视图或者根视图是NavigationController。自己定义个子类继承UINavigationController,然后将要展现的视图包装到这个子类中,这样就可以使这个视图是个NavigationController了。提供的这个方法有很好的好处,就是可以统一的控制各个视图的屏幕旋转。
 
 
在这里简单的说下控制屏幕旋转的方法:(下面三个方法放到继承UINavigationController类的子类中就可以实现控制各个视图的屏幕旋转)
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     UIViewController *nsClass = self.visibleViewController;
     NSString *className = NSStringFromClass([nsClass class]);
     if ([className isEqualToString:@"VideoViewController"])
    {    
         return [self shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 
/**
UIInterfaceOrientationPortrait  = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft   = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight  = UIDeviceOrientationLandscapeLeft
**/
 
----------------------------------------------------------------------------------------------------------------------------------------------
 
- (BOOL)shouldAutorotate
{
    return YES;
}
 
- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *nsClass = self.visibleViewController;
    NSString *className = NSStringFromClass([nsClass class]);
    if ([className isEqualToString:@"VideoViewController"])
    {     
        return [nsClass supportedInterfaceOrientations];
    }  
    return UIInterfaceOrientationMaskPortrait;
 
/*
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait)
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft)
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight)   
UIInterfaceOrientationMaskPortraitUpsideDown = (1<<UIInterfaceOrientationPortraitUpsideDown)
UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | 
                                                 UIInterfaceOrientationMaskLandscapeRight)   
UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait |      
                                                          UIInterfaceOrientationMaskLandscapeLeft | 
                                                           UIInterfaceOrientationMaskLandscapeRight |                            
                                                            UIInterfaceOrientationMaskPortraitUpsideDown)
UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait |  
                                                           UIInterfaceOrientationMaskLandscapeLeft  | 
                                                               UIInterfaceOrientationMaskLandscapeRight),
*/
}
 
shouldAutorotateToInterfaceOrientation在ios6之前可以使用,到ios6后包括ios6和后就淘汰了,提供shouldAutorotate和supportedInterfaceOrientations两个方法来控制屏幕的旋转。
posted on 2013-02-06 09:26  ssy黑桃a  阅读(4345)  评论(0编辑  收藏  举报