2013-09-16 28 views
11

Tôi đang thực hiện các chuyển đổi tùy chỉnh và loại bỏ tùy chỉnh và có một số vấn đề với quá trình chuyển đổi. Những gì tôi muốn làm là lặp lại hình ảnh động sâu sắc tuyệt vời này trong iOS 7 (khi chúng tôi mở/đóng một số ứng dụng). Tôi có bộ điều khiển thứ nhất và thứ hai. Tất cả các hình động đều nằm trong bộ điều khiển Đầu tiên (nó hỗ trợ UIViewControllerTransitioningDelegate và UIViewControllerAnimatedTransitioning). Vì vậy, tôi chỉ kiểm tra: nếu nó được trình bày - Tôi đang làm một hình ảnh động (mở rộng xem đầu tiên và thứ hai), nếu nó được loại bỏ - Tôi đang làm một hình ảnh động khác (mở rộng xuống lần đầu tiên và thứ hai). Hoạt ảnh hiện tại hoạt động tốt, sự cố xảy ra khi loại bỏ hoạt ảnh. Trong một số lý do khi tôi giảm kích thước bộ điều khiển thứ hai của tôi (nó là UINavigationController), tôi thấy nền đen phía sau nó (và nó sai, bởi vì tôi muốn nhìn thấy bộ điều khiển đầu tiên của tôi trong khi nó giảm tỷ lệ xuống). Đây là mã của tôi từ First Controllerios 7 tùy chỉnh hiện tại và loại bỏ quá trình chuyển đổi

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { 
    UIView *transitionView = [transitionContext containerView]; 

    id toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    id fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 

    BOOL isPresenting; 

    isPresenting = [toViewController isKindOfClass:[UINavigationController class]]; 

    UINavigationController *navigator = isPresenting ? toViewController : fromViewController; 

    if (isPresenting) { 
     [transitionView addSubview:navigator.view]; 
     navigator.view.transform = CGAffineTransformMakeScale(0.1, 0.1); 
     navigator.view.alpha = 0; 
    } 

    navigator.view.center = self.startButton.center; 

    void(^AnimationBlock)(void) =^{ 
     if (isPresenting) { 
      navigator.view.transform = CGAffineTransformMakeScale(1, 1); 
      self.view.transform = CGAffineTransformMakeScale(4, 4); 
      navigator.view.alpha = 1; 
      self.startButton.alpha = 0; 
     } else { 
      navigator.view.transform = CGAffineTransformMakeScale(0.1, 0.1); 
      self.view.transform = CGAffineTransformMakeScale(1, 1); 
      navigator.view.alpha = 0; 
      self.startButton.alpha = 1; 
     } 
    }; 

    [UIView animateWithDuration:1 
          delay:0.0f 
     usingSpringWithDamping:50.0 
      initialSpringVelocity:4 
         options:UIViewAnimationOptionLayoutSubviews 
        animations:^{ 
         AnimationBlock(); 
    } completion:^(BOOL finished) { 
     [transitionContext completeTransition:YES]; 
     if (!isPresenting) { 
      [navigator.view removeFromSuperview]; 
     } 
    }]; 
} 

- (void)completeTransitionInContext:(id<UIViewControllerContextTransitioning>)transitionContext{ 
    [transitionContext completeTransition:YES]; 
} 


- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ 
    return 1; 
} 


- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 
    return self; 
} 

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { 
    return self; 
} 

Hãy cho tôi biết nếu tôi nên cung cấp thêm một số mã hoặc màn hình. Cảm ơn bạn trước!

+0

API iOS 7 vẫn còn trong NDA, cho đến khi tính khả dụng công khai (18 bộ) – Vinzzz

+0

Tôi gặp sự cố tương tự và API iOS7 không thuộc NDA nữa ... Bạn có thể giải thích cách giải quyết không? Cảm ơn! – veducm

+0

Vẫn không biết câu trả lời: ( –

Trả lời

3

Tôi nghĩ bạn nên sử dụng hai lớp riêng biệt AnimationController cho Hiện tại và Loại bỏ hoạt ảnh và triển khai UIViewControllerTransitioningDelegate (animationControllerForPresentedControlleranimationControllerForDismissedController) bên trong Chế độ xem phụ huynh của bạn.

Để tạo một AnimationController chỉ cần phân lớp NSObject và triển khai UIViewControllerAnimatedTransitioning tại đó.

Hy vọng điều đó sẽ hữu ích.

10

Bạn cần đặt modalPresentationStyle = UIModalPresentationTùy chỉnh trên toVC trước khi trình bày nó nếu bạn muốn giữ từVC trong hệ thống phân cấp cửa sổ sau khi quá trình chuyển đổi hiện tại hoàn tất.

Xem việc triển khai mã mẫu của tôi cho Phiên WWDC 218: Chuyển đổi tùy chỉnh bằng cách sử dụng bộ điều khiển chế độ xem. Nếu bạn nhấp vào 'Tùy chọn', bạn sẽ thấy loại chuyển đổi này. Các mã có liên quan là trong SOLViewController.m prepareForSegue: và SOLOptionsTransitionAnimator.m

https://github.com/soleares/SOLPresentingFun

6

Khi bạn trình bày các tùy chỉnh VC, bạn nên sử dụng: vc.modalPresentationStyle = UIModalPresentationCustom; nhưng, nếu bạn gõ sai để vc.modalTransitionStyle = UIModalPresentationCustom; bạn sẽ nhận được a nền đen phía sau VC tùy chỉnh.

+1

Thanx để đăng bài. Đã lưu giờ của tôi. – smileBot