8

Trong mã của tôi Tôi đang sử dụng presentViewController gọi viewController thứ hai của tôipresentViewController hoạt hình chuyển

[self presentViewController:secondController animated:YES completion:nil]; 

Khi tôi gọi tôi cần phải chứng minh trái sang hình ảnh động đúng (như trong navigationController)

Tôi không muốn để sử dụng navigationController nhưng tôi cần hoạt ảnh tương tự như navigationController trong presentViewController ...

Trả lời

12

Thêm dòng mã này trước khi trình bày bộ điều khiển xem

secondController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
secondController.modalPresentationStyle = UIModalPresentationFullScreen; 

// Take a look at this enum 

typedef enum { 
    UIModalTransitionStyleCoverVertical = 0, 
    UIModalTransitionStyleFlipHorizontal, 
    UIModalTransitionStyleCrossDissolve, 
    UIModalTransitionStylePartialCurl, 
} UIModalTransitionStyle; 
+0

Không, nó không hoạt động, chỉ đơn giản là không có hoạt ảnh. secondController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // Hãy xem enum này typedef enum { UIModalTransitionStyleCoverVertical = 0, UIModalTransitionStyleFlipHorizontal, UIModalTransitionStyleCrossDissolve, UIModalTransitionStylePartialCurl, } UIModalTransitionStyle; [self presentViewController: secondController animated: YES completion: nil]; –

+0

@SubramanianRaj Thêm UIModalPresentationStyle quá – Ch0k0l8

+0

@SubramanianRaj Kiểm tra mã mới – Ch0k0l8

5

cho Swift

Xác định hình ảnh động loại


enum UIModalTransitionStyle : Int { 
    case CoverVertical = 0 
    case FlipHorizontal 
    case CrossDissolve 
    case PartialCurl 
} 

Làm thế nào để sử dụng


let vc : PageHomeViewController = storyboard!.instantiateViewControllerWithIdentifier("PageHomeViewController") as! PageHomeViewController 
vc.modalTransitionStyle = .FlipHorizontal 
self.presentViewController(vc, animated: true, completion: nil) 
-1

@swiftboy Câu trả lời là hầu hết Corre ct. Bạn không cần phải khai báo enum và bạn có thể gọi nó trực tiếp.

let vc : PageHomeViewController = 
storyboard!.instantiateViewControllerWithIdentifier("PageHomeViewController") 
as! PageHomeViewController 
vc.modalTransitionStyle = .FlipHorizontal 
self.presentViewController(vc, animated: true, completion: nil) 
+0

Đây chỉ là một bản sao của câu trả lời khác cho câu hỏi này. Vui lòng chỉ thêm câu trả lời nếu bạn có nội dung mới để thêm. – FluffyKitten

0

Tất cả những điều trên cũng có thể đạt được trong bảng phân cảnh mà không phải viết mã. Nhấp vào segue của bạn liên kết các bộ điều khiển xem của bạn, sau đó chọn tab Attributes Inspector trong menu bên phải. Trong trình đơn thả xuống Loại, chọn 'Trình bày theo phương thức'. Một tập hợp các tùy chọn khác sẽ xuất hiện. Trong menu thả xuống Chuyển tiếp, bạn sẽ có thể chọn bất kỳ danh sách nào được liệt kê ở trên. Segue Attributes Inspector

0

Quyết định của tôi để giải quyết hoạt ảnh "che ngang" như phương pháp đẩy UINavigationViewController bằng cách sử dụng UIViewControllerTransitioningDelegate.

1.Tạo chuyển tiếp tùy chỉnh.

Tiêu đề

@interface CoverHorizontalTransition: NSObject<UIViewControllerAnimatedTransitioning> 
@property (assign, nonatomic) BOOL dismiss; 
@end 

Thực hiện

@implementation CoverHorizontalTransition 

- (void)animateTransition:(nonnull id<UIViewControllerContextTransitioning>)transitionContext 
{ 
    UIViewController *fromViewController; 
    fromViewController = 
    [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 

    UIViewController *toViewController; 
    toViewController = 
    [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    UIView *containerView = transitionContext.containerView; 

    CGRect animatedViewFrame; 
    animatedViewFrame = containerView.bounds; 
    animatedViewFrame.origin = CGPointMake(CGRectGetWidth(animatedViewFrame), 0); 

    [containerView addSubview:toViewController.view]; 

    if (_dismiss) { 
     [containerView bringSubviewToFront:fromViewController.view]; 

     [UIView 
     animateWithDuration:[self transitionDuration:transitionContext] 
     animations:^{ 
      fromViewController.view.frame = animatedViewFrame; 
     } completion:^(BOOL finished) { 
      [containerView.superview addSubview:toViewController.view]; 
      [fromViewController.view removeFromSuperview]; 
      [transitionContext completeTransition:YES]; 
     }]; 
    } else { 
     toViewController.view.frame = animatedViewFrame; 

     [UIView 
     animateWithDuration:[self transitionDuration:transitionContext] 
     animations:^{ 
      toViewController.view.center = containerView.center; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:YES]; 
     }]; 
    } 
} 

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

@end 

2.Create chuyển tiếp đại biểu.

@implementation CustomViewControllerTransitioningDelegate 

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

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed 
{ 
    CoverHorizontalTransition *transition; 
    transition = [CoverHorizontalTransition new]; 
    transition.dismiss = YES; 

    return transition; 
} 

@end 

Mẫu sử dụng.

... 
// Save delegate to strong property 
secondController.customTransitioningDelegate = 
[BaseViewControllerTransitioningDelegate new]; 

secondController.transitioningDelegate = 
secondController.customTransitioningDelegate; 
secondController.modalPresentationStyle = UIModalPresentationCustom; 

[self presentViewController:secondController animated:YES completion:nil]; 

Mã này hoạt động cho iOS 10 trở lên.

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