Apple Documentation ( https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion :) Says "On iPhone and iPod touch, the presented view is always full screen." But in iOS 7, there is the custom view controller transitioning API. There are already many demos that show the "presentedViewController" can be any size we want. Is the Apple's Doc not true in this case ?
I believe Apple is still correct although perhaps misleading. It will be presented full screen by default, but if you provide a custom transition delegate you can do whatever you want to the frame, etc...
What Apple means by full screen (in this context, I think), is that it's edges extend to the device's height & width maximums. Previously it would be restricted by things like the navbar or other toolbars that may have been added, but by default in iOS 7 they don't respect them any more.
However with a custom transition, you can now have a smaller view controller overlay another view controller by changing the size of it's frame during the transition. See Teehan & Lax's awesome transition API post here for an example:
http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
Here's the -animateTransition
method for setting the frame on the to view controller to a value that's clearly not going to be full screen. Note the lines where the endFrame
variable is set up:
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
// Grab the from and to view controllers from the context
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
// Set our ending frame. We'll modify this later if we have to
CGRect endFrame = CGRectMake(80, 280, 160, 100); // <- frame is only 160 x 100
if (self.presenting) {
fromViewController.view.userInteractionEnabled = NO;
[transitionContext.containerView addSubview:fromViewController.view];
[transitionContext.containerView addSubview:toViewController.view];
CGRect startFrame = endFrame;
startFrame.origin.x += 320;
toViewController.view.frame = startFrame;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
toViewController.view.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
else {
toViewController.view.userInteractionEnabled = YES;
[transitionContext.containerView addSubview:toViewController.view];
[transitionContext.containerView addSubview:fromViewController.view];
endFrame.origin.x += 320;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
fromViewController.view.frame = endFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
}
So, when providing a custom transition the view controller you transition from and to will have whichever edges and/or frames that you specify for them. They don't suddenly become full screen when you begin a custom transition, so Apple is right, but probably not completely thorough in it's explanation of the present method's description.
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.