6

Tôi có một số UINavigationController với gốc UIViewController ("root").iOS8 - Sau khi đẩy UIViewController trên UINavigationController và xoay thiết bị, kích thước không đúng trong bộ điều khiển xem trước

Trình điều khiển chế độ xem gốc đẩy khác UIViewController "con". Khi "con" UIViewController nằm trên màn hình, tôi xoay thiết bị và mong muốn bộ điều khiển chế độ xem "gốc" thay đổi kích thước cho phù hợp nhưng điều này không xảy ra. Sau khi đặt điểm ngắt trong bộ điều khiển chế độ xem gốc:

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 
} 

Tôi thấy kích thước sai và trình điều khiển chế độ xem gốc không điều chỉnh đúng cho thay đổi.

Có ai trải qua hành vi này không?

Mã này là như vậy:

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 


} 

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { 
/// The size is wrong if this view controller is off screen 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 
} 
- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

enter image description here

Dưới đây là một màn hình in của NSLog kích thước sau khi xoay thiết bị - Đây là từ mô phỏng nhưng hành vi này là như nhau trên thiết bị.

enter image description here

+0

Nhật ký kích thước của bạn là gì, bạn mong đợi điều gì? – gabbler

+0

Tôi sẽ thêm một màn hình in - sau khi tôi đã xoay thiết bị vài lần. Lưu ý rằng kích thước luôn giống nhau. –

+0

Có, nó luôn luôn có cùng kích thước, có vẻ như bộ điều khiển Gốc Xem không xoay chút nào. – gabbler

Trả lời

0

Có thể chỉ xoay cửa sổ. Nếu bạn in nó như thế này, nó luôn luôn đúng như tôi đã thử nghiệm.

[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) 
{ 

} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) 
{ 
    UIWindow *screen = [[[UIApplication sharedApplication] delegate] window]; 
    CGSize mainWindowSize = screen.bounds.size; 
    NSLog(@"Main window size is %@",NSStringFromCGSize(mainWindowSize)); 

}]; 
+0

Đó là một hack. Tôi không muốn đặt điều đó trong 20 bộ điều khiển xem –

+0

Tất cả những gì đang đổ ra kích thước hiện tại cho nhật ký. Không có gì có hiệu lực trong mã này. –

+0

@NormanH, mã này hoạt động cho tôi, nó được đặt trong bộ điều khiển xem trước đó, chế độ xem tắt màn hình, nếu bạn xoay chế độ xem hiện tại, nhật ký là đúng. – gabbler

2

Cùng một vấn đề về dự án của tôi. Dường như UINavigationController và UITabBarController (có thể là tất cả viewController?) Cho trẻ có kích thước sai khi bạn gọi:

'[super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];'

Tôi đã khắc phục vấn đề bằng cách ghi đè 'viewWillTransitionToSize: withTransitionCoordinator:' trong tabBarController và bảng điều khiển thanh điều hướng của tôi (cùng mã trong cả hai).

- (void)viewWillTransitionToSize:(CGSize)size 
     withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 
{ 
    for (UIViewController* aViewController in self.viewControllers) 
    { 
     [aViewController viewWillTransitionToSize:size 
         withTransitionCoordinator:coordinator]; 
    } 

    if ([self presentedViewController]) 
    { 
     [[self presentedViewController] viewWillTransitionToSize:size 
             withTransitionCoordinator:coordinator]; 
    } 
} 

Tôi không chắc đây là cách tốt nhất, nếu bạn tìm thấy điều gì đó tốt hơn, hãy cho tôi biết.

Các vấn đề liên quan