开发者

UIViewAutoresizingNone: Resize after rotation

i have a simple structure for IPAD with an AppDelegate that include a view from a viewController :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    ClockVC *clockVC = [[ClockVC alloc]init];
    clockVC.view.frame = CGRectMake(100, 100, clockVC.view.bounds.size.width, clockVC.view.bounds.size.height);

    [self.window addSubview:clockVC.view];
    [self.window makeKeyAndVisible];

    return YES;
}

clockVC has a viewDidLoad defined by this code :

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.autoresizingMask = UIViewAutoresizingNone;
    self.view.autoresizesSubviews = UIViewAutoresizingNone;
}

Bounds of clockVC are defined by IB and override in application:didFinishLaunching... Width and Height are respectively 200 and 150.

ClockVC implements method for one-step auto-rotation : /

/ Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
    开发者_开发问答 [UIView animateWithDuration:0.5 
                     animations:^{self.view.alpha = 0;}
     ];
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [UIView animateWithDuration:1 
                     animations:^{self.view.alpha = 1;}
     ];
}

At the first load the page is correctly viewed and clockVC view is in position. When i rotate clockVC view (whose autoResizeMask is set to UIViewAutoresizingNon)resize to take the entire screen.

Why ?? i'd like to mantain initial size.

Here screenshots of my problem. Before rotation:

UIViewAutoresizingNone: Resize after rotation

After Rotation:

UIViewAutoresizingNone: Resize after rotation


Don't use the root view for this, add a subview to the view controller's view instead. UIViewControllers are typically designed to fill the entire space of their container (the window in this case).

For example, if you would add a UIViewController to a UINavigationController, the navigation controller takes over the responsibility to size the view controller's view according to the navigation controller's layout (whether the navigation bar is visible etc.). I'm not sure how exactly UIWindow behaves (I think this is not very clearly documented), but in a lot of places in the SDK, a view controller's parent is responsible for the positioning and size of its children (UIPopoverController, UITabBarController et.al.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜