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兩個方法來控制屏幕的旋轉。
