拥有UIViewController1
和UIViewController2
我想以UIViewController2
形式提供UIViewController1
。我可以这样做:
self.presentViewController:animated:completion
我想要做的是呈现UIViewController2
,使其大小:100x100,并且像弹出窗口一样位于屏幕的中心。当UIViewController2
出现时,UIViewController2
的周围应显示某种玻璃层,您可以看到UIViewController1
模糊。
我该怎么做?
答案 0 :(得分:0)
实施UIViewControllerTransitioningDelegate
这是一个教程:
http://www.raywenderlich.com/96062/custom-view-controller-presentation-transitions-swift
答案 1 :(得分:0)
在UIViewController中添加UIView2 100x100
的.m
@property (weak, nonatomic) IBOutlet UIView *view2;
·H
- (void)viewDidLoad
{
[super viewDidLoad];
self.view2.hidden = YES;
}
从按钮或代码调用view2:
[self showView2];
并表明:
-(void) showView2
{
self.view2.hidden = NO;
self.view.opaque = NO;
self.view.alpha = 0.5;
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:1];
}
答案 2 :(得分:0)
你必须使用transitioningDelegate for UIViewController。你有一个非常好的例子,类似于你想要实现的目标:
https://github.com/schneiderandre/popping
使用PresentingAnimator类来了解CustomTransitionViewController的呈现方式。您不必在动画中使用POP框架,只需使用UIView类方法为框架设置动画:
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
重要:您必须使用UIModalPresentationCustom将presentViewController显示在显示的后面。