![](/img/trans.png)
[英]How can I perform a present modally segue on a view controller that is presented modally?
[英]How can I present a UIViewController modally showing presented Controller in the Blured Background?
有一個UIViewController1
和UIViewController2
我想以模態形式在UIViewController1
呈現UIViewController2
。 我可以這樣做:
self.presentViewController:animated:completion
我想做的是呈現UIViewController2
,使其具有以下大小:100x100,並像彈出窗口一樣位於屏幕的中央。 當UIViewController2
是目前的周邊UIViewController2
應該表現出一定的玻璃層,在那里你可以看到UIViewController1
模糊。
我怎樣才能做到這一點?
在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];
}
您必須對UIViewController使用transitioningDelegate。 您有一個很好的例子,類似於您要在此處實現的目標:
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來使presentingViewController在所呈現的控件后面可見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.