自定义UIPresentationController
来源:互联网 发布:ubuntu解压tar.gz命令 编辑:程序博客网 时间:2024/05/16 07:12
首先设置设置需要modal的控制器的代理;并且设置他的present模式为自定义
比如:
vc.modalPresentationStyle = UIModalPresentationCustom;vc.transitioningDelegate = self;
实现UIViewControllerTransitioningDelegate的代理方法;可以写一个单例来包含他们。并且VC的代理设为[objcet shareObject];
/** 由返回的对象控制需要展示的控制器;*/- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{ return [[ZGPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];}/** 由返回的对象控制Presented时的动画;*/- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{ ZGAnimatedTransitioning *anim = [[ZGAnimatedTransitioning alloc] init]; anim.presented = YES; return anim;}/** 由返回的控制器控制dismissed时的动画;*/- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{ ZGAnimatedTransitioning *anim = [[ZGAnimatedTransitioning alloc] init]; anim.presented = NO; return anim;}
重写presentation方法的类ZGPresentationController
@implementation ZGPresentationController//- (CGRect)frameOfPresentedViewInContainerView//{//// return CGRectMake(0, 50, self.containerView.frame.size.width, self.containerView.frame.size.height - 100);// return CGRectInset(self.containerView.bounds, 0, 100);//}- (void)presentationTransitionWillBegin{// NSLog(@"presentationTransitionWillBegin"); self.presentedView.frame = self.containerView.bounds; [self.containerView addSubview:self.presentedView];}- (void)presentationTransitionDidEnd:(BOOL)completed{// NSLog(@"presentationTransitionDidEnd");}- (void)dismissalTransitionWillBegin{// NSLog(@"dismissalTransitionWillBegin");}- (void)dismissalTransitionDidEnd:(BOOL)completed{// NSLog(@"dismissalTransitionDidEnd"); [self.presentedView removeFromSuperview];}@end
重写AnimatedTransitioning方法的类ZGAnimatedTransitioning
#import <UIKit/UIKit.h>@interface ZGAnimatedTransitioning : NSObject <UIViewControllerAnimatedTransitioning>//一定要遵守这个协议@end
const CGFloat duration = 1.0;@implementation ZGAnimatedTransitioning#pragma mark - UIViewControllerAnimatedTransitioning- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ return duration;}- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{ if (self.presented) { UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];// toView.layer.transform = CATransform3DMakeRotation(M_PI_2, 1, 1, 0);// toView.y = -toView.height; toView.x = toView.width; [UIView animateWithDuration:duration animations:^{// toView.y = 0; toView.x = 0;// toView.layer.transform = CATransform3DIdentity; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }]; } else { [UIView animateWithDuration:duration animations:^{ UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];// fromView.y = -fromView.height; fromView.x = -fromView.width;// fromView.layer.transform = CATransform3DMakeRotation(M_PI_2, 1, 1, 0); } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }]; }}@end
到时候只要将这三个类封装,然后再调用我一开始提到的两句即可自定义一个modal了。具体的modal各种形态的修改在ZGAnimatedTransitioning和ZGPresentationController类中。
0 0
- 自定义UIPresentationController
- UIPresentationController自定义转场动画
- UIPresentationController
- UIPresentationController
- UIPresentationController
- ios8中 利用UIPresentationController 自定义转场
- UIPresentationController 注意事项
- UIPresentationController简介
- iOS8的UIPresentationController
- UIPresentationController 教程:入门
- iOS UIPresentationController实现弹出视图
- iOS8新特性 UIPresentationController(一)
- iOS8新特性 UIPresentationController(一) popover、alert、action sheet与search的新特性
- iOS8新特性 UIPresentationController(一) popover、alert、action sheet与search的新特性
- iOS关于UIPresentationController 在视图上面创建一个UIViewController并改变大小
- UIPresentationController 蒙版阴影,看我就足够了(特简单)
- 自定义
- 自定义
- Leetcode:4. Median of Two Sorted Arrays
- C#控制台基础 创建文件夹
- 常用正则表达式实例
- 第三周 项目1-顺序表的基本运算
- 青岛网赛 1006 HDU 5883 The Best Path
- 自定义UIPresentationController
- Linux文件压缩与解压总结
- 003 个位数统计
- C语言调用Window/Linux上的各种应用程序
- 关于屏幕适配问题
- Code forces 699B
- E/dalvikvm: Could not find class
- Struts2、Spring4与Hibernate5三大框架整合
- WebService(4)_Apache CXF 服务端四种发布方式(图文详解实例)