2012-10-26 29 views
0

之前IOS 6我用下面的代碼來呈現模態的視圖與定製尺寸:變遷大小與presentViewController正確:動畫:完成:

- (void) showModalViewWithController:(GUIViewController*) _viewController { 
    [UIView beginAnimations:@"" context:nil]; 
    [self presentModalViewController:_viewController animated:YES]; 
    _viewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
    _viewController.view.superview.frame = CGRectMake(
     _viewController.view.superview.frame.origin.x, 
     _viewController.view.superview.frame.origin.y, 
     700.0f, 
     self.view.frame.size.height - 80.f); 
    _viewController.view.superview.center = self.view.center; 

    [UIView commitAnimations]; 
} 

現在我有改變功能

- (void)presentModalViewController: (UIViewController *)viewControllerToPresent animated:(BOOL)flag 

- (void)presentViewController: (UIViewController *)viewControllerToPresent animated: (BOOL)flag completion: (void (^)(void))completion 

不幸的是調整大小後查不正常工作如下所示:

- (void) showModalViewWithController:(GUIViewController*) _viewController { 
    [self presentViewController:_viewController animated:YES completion:^(){ 
     [UIView beginAnimations:@"" context:nil]; 
     _viewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
     _viewController.view.superview.frame = CGRectMake(
      _viewController.view.superview.frame.origin.x, 
      _viewController.view.superview.frame.origin.y, 
      700.0f, 
      self.view.frame.size.height - 80.f); 
     _viewController.view.superview.center = self.view.center; 
     [UIView commitAnimations]; 
    }]; 
} 

因爲模式視圖在幀操作之前呈現,並且在調用完成塊之後跳轉。

如何處理?

由於提前,

米哈爾

+0

發現你試過保持它和以前一樣,並留下完成塊空白?將所有代碼添加到塊中應該完全按照您的說法進行操作,呈現視圖然後再進行動畫演示。 – TheJer

+0

是的,我試圖不使用完成塊,但它只適用於iOS 5. iOS 6要求額外的屏幕旋轉以正確重畫視圖。 – Kaktusiarz

+0

嗨!任何解決方案我面臨同樣的問題。謝謝 – Frade

回答

0

我不知道是什麼原因結束塊動畫會跳。我從來沒有使用過[UIView beginAnimations:context:]方法。我通常會調用基於塊的動畫方法,如[UIView animateWithDuration:animations:completion:]。這是因爲在iOS 4及以上版本中不鼓勵使用beginAnimations方法。

我會嘗試改變你的動畫來使用基於塊的方法。提交動畫後可能會出現一些奇怪的線程問題。

我發現它很有趣,你正在調整的大小後顯示它,而不是事先調整大小。

0

AHKNavigationController * navigationController = [[AHKNavigationController alloc] initWithRootViewController:moreOverView];

[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];

navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    navigationController.navigationBarHidden=YES; 
    if([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) 
    { 
     [self presentViewController:navigationController animated:YES completion:^{ 
      [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 
        //Make the modal bigger than normal 
       navigationController.view.superview.frame = CGRectMake(
                     navigationController.view.superview.frame.origin.x, 
                     navigationController.view.superview.frame.origin.y, 
                     540, 
                     622 
                     ); 
      } completion:^(BOOL finished) { 
      }]; 
     }]; 
    } 
    else{ 
     [self presentViewController:navigationController animated:YES completion:nil]; 
     navigationController.preferredContentSize = CGSizeMake(540,622); 
     navigationController.view.superview.center = self.view.center; 
    } 
    navigationController.view.superview.autoresizingMask = 
    UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleBottomMargin; 

其中AHKNavigationController在https://github.com/fastred/AHKNavigationController

相關問題