2011-07-05 112 views

回答

3

为什么要为两个方向使用两个视图?您可以设置控件的autoresizemask属性,如果纵向和横向两种模式都具有类似的控件以显示在相同的位置。否则,您需要在

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

使用两个视图,或者你可以拥有的UIDevice

的通知
UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification; 

- (void)beginGeneratingDeviceOrientationNotifications;  // nestable 
- (void)endGeneratingDeviceOrientationNotifications; 
2

只需在您的控制器中为这两个方向分配代表。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
3

假设你已经设置-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation来回报您的支持方向,你可以使用都可以在UIViewController设置检查方向更改下面的方法,然后设置你的观点:

// called just before the user interface starts to rotate - my advice would be to use this method to save a copy of the current orientation. 
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

// called after the interface has finished rotating. Here, you can compare the old orientation with the new one - if you went from portrait to landscape, then update your views accordingly. 
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

希望这有助于!