Having a UIViewController1
and UIViewController2
I want to present UIViewController2
in UIViewController1
modally. I can do this with:
self.presentViewController:animated:completion
What I want to do is present the UIViewController2
such that it has size: 100x100 and is positioned in the center of the screen like a popup. When UIViewController2
is present the surrounding of the UIViewController2
should show some kind of glass layer where you can see the UIViewController1
blurred.
How can I do that?
Implement the UIViewControllerTransitioningDelegate
Here is a tutorial:
http://www.raywenderlich.com/96062/custom-view-controller-presentation-transitions-swift
Add UIView2 100x100 in UIViewController
.m
@property (weak, nonatomic) IBOutlet UIView *view2;
.h
- (void)viewDidLoad
{
[super viewDidLoad];
self.view2.hidden = YES;
}
Call view2 from button or code:
[self showView2];
And show it:
-(void) showView2
{
self.view2.hidden = NO;
self.view.opaque = NO;
self.view.alpha = 0.5;
self.view.backgroundColor = [UIColor colorWithWhite:0.3 alpha:1];
}
You have to use the transitioningDelegate for UIViewController. You have a very good example, similar to what you want to achieve here:
https://github.com/schneiderandre/popping
Take a look at how CustomTransitionViewController is presenting using the PresentingAnimator class. You don't have to use POP Framework at for your animations, you can just animate the frame with the UIView class method:
+ (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);
Important :you have to use UIModalPresentationCustom to have the presentingViewController visible behind the presented one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.