Bri*_*tta 15 email objective-c ios
我正在iOS 8上构建一个应用程序,我希望在创建新的电子邮件/消息时复制iOS的邮件应用程序的功能.如下所示:compose视图控制器显示在收件箱视图控制器的顶部,但是compose vc不占用整个屏幕.有没有比使用视图控制器的框架进行黑客攻击更容易的方法?谢谢!

Bri*_*tta 16
这个效果可以UIPresentationController在iOS 8中实现.苹果有关于这个主题的WWDC '14视频以及在这篇文章底部找到的一些有用的示例代码(我在这里发布的原始链接不再有效).
*该演示称为"LookInside:演示控制器适应性和自定义动画对象".Apple的代码中存在一些与过时的API使用相对应的错误,可以通过将损坏的方法名称(在多个位置)更改为以下内容来解决:
initWithPresentedViewController:presentingViewController:
以下是您可以在iOS 8邮件应用程序上复制动画的操作.为了达到预期的效果,下载我上面提到的项目,然后你要做的就是改变一些事情.
首先,转到AAPLOverlayPresentationController.m并确保已实现该frameOfPresentedViewInContainerView方法.我看起来像这样:
- (CGRect)frameOfPresentedViewInContainerView
{
CGRect containerBounds = [[self containerView] bounds];
CGRect presentedViewFrame = CGRectZero;
presentedViewFrame.size = CGSizeMake(containerBounds.size.width, containerBounds.size.height-40.0f);
presentedViewFrame.origin = CGPointMake(0.0f, 40.0f);
return presentedViewFrame;
}
Run Code Online (Sandbox Code Playgroud)
关键是你希望presentViewController的框架从屏幕顶部偏移,这样你就可以实现一个视图控制器与另一个视图控制器重叠的外观(没有模态完全覆盖presentViewController).
接下来,animateTransition:在AAPLOverlayTransitioner.m中找到该方法,并将代码替换为下面的代码.您可能希望根据自己的代码调整一些内容,但总体而言,这似乎是解决方案:
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *fromView = [fromVC view];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = [toVC view];
UIView *containerView = [transitionContext containerView];
BOOL isPresentation = [self isPresentation];
if(isPresentation)
{
[containerView addSubview:toView];
}
UIViewController *bottomVC = isPresentation? fromVC : toVC;
UIView *bottomPresentingView = [bottomVC view];
UIViewController *topVC = isPresentation? toVC : fromVC;
UIView *topPresentedView = [topVC view];
CGRect topPresentedFrame = [transitionContext finalFrameForViewController:topVC];
CGRect topDismissedFrame = topPresentedFrame;
topDismissedFrame.origin.y += topDismissedFrame.size.height;
CGRect topInitialFrame = isPresentation ? topDismissedFrame : topPresentedFrame;
CGRect topFinalFrame = isPresentation ? topPresentedFrame : topDismissedFrame;
[topPresentedView setFrame:topInitialFrame];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0
usingSpringWithDamping:300.0
initialSpringVelocity:5.0
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
animations:^{
[topPresentedView setFrame:topFinalFrame];
CGFloat scalingFactor = [self isPresentation] ? 0.92f : 1.0f;
//this is the magic right here
bottomPresentingView.transform = CGAffineTransformScale(CGAffineTransformIdentity, scalingFactor, scalingFactor);
}
completion:^(BOOL finished){
if(![self isPresentation])
{
[fromView removeFromSuperview];
}
[transitionContext completeTransition:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
目前,我还没有针对iOS 8之前的操作系统版本提供解决方案,但如果您想出一个,请随时添加答案.谢谢.
更新:
似乎上面的链接不再有效.可在此处找到相同的项目:https://developer.apple.com/library/ios/samplecode/LookInside/LookInsidePresentationControllersAdaptivityandCustomAnimatorObjects.zip
更新 - 2018年6月:
@ChristopherSwasey更新了repo以与Swift 4兼容.感谢Christopher!
对于未来的旅行者来说,Brian的帖子非常棒,但是有很多关于UIPresentationController(它促进了这个动画)的很好的信息我强烈建议你研究一下.我创建了一个包含iOS Mail应用程序组合动画的Swift 1.2版本的repo.我还在ReadMe中提供了大量相关资源.请在此处查看:https:
//github.com/kbpontius/iOSComposeAnimation