- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 UIViewcontrollerAnimatedTransitioning 为 PopUp ViewController 呈现动画。我已经创建了一个从 TableViewCell 到我的 Viewcontroller 的 Modal Segue
在 PopupPresentAnimationController(实现 UIViewcontrollerAnimatedTransitioning)中我有
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
[fromViewController addChildViewController:toViewController];
toViewController.view.frame = fromViewController.view.frame;
[fromViewController.view addSubview:toViewController.view];
[toViewController didMoveToParentViewController:fromViewController];
NSTimeInterval duration = [self transitionDuration:transitionContext];
[UIView animateWithDuration:duration delay:0.0 usingSpringWithDamping:0.6 initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
fromViewController.view.alpha = 0.5;
} completion:^(BOOL finished) {
fromViewController.view.alpha = 1.0;
[transitionContext completeTransition:YES];
}];
}
PopUpViewController 的背景为黑色,不透明度为 50%,当它看起来所有“有效”但在动画结束后,屏幕变为黑色。
更新 1:
UIViewController *fromViewController =[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
CGRect initialFrame = toViewController.view.frame;
initialFrame.origin.y = toViewController.view.frame.size.height;
toViewController.view.frame = initialFrame;
[container insertSubview:toViewController.view aboveSubview:fromViewController.view];
NSTimeInterval duration = [self transitionDuration:transitionContext];
[UIView animateWithDuration:duration delay:0 options:0 animations:^{
CGRect newFrame = toViewController.view.frame;
newFrame.origin.y = 0;
toViewController.view.frame = newFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
更新 2在 prepareForSegue 中,我添加了以下行
controller.modalPresentationStyle = UIModalPresentationCustom; // controller is the destination
有了这条线,黑色就不再是黑色了!
最佳答案
您遇到的问题是您将toViewController
添加到fromViewController
。当动画结束时,toViewController
被移除,您的 fromViewController
也被移除。处理这个问题的正确方法是使用上下文提供的容器 View :
UIView *container = [transitionContext containerView];
这是一个如何进行弹出转换的示例:
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
if (!self.beingDismissed) {
//Make controller hidden so it can slide in
CGRect initialFrame = toViewController.view.frame;
initialFrame.origin.y = toViewController.view.frame.size.height;
toViewController.view.frame = initialFrame;
[container insertSubview:toViewController.view aboveSubview:fromViewController.view];
}
[UIView animateKeyframesWithDuration:0.5 delay:0 options:0 animations:^{
if (!self.beingDismissed) {
//Show view controller
CGRect newFrame = toViewController.view.frame;
newFrame.origin.y = 0;
toViewController.view.frame = newFrame;
} else {
//Hide view controller
CGRect newFrame = fromViewController.view.frame;
newFrame.origin.y = fromViewController.view.frame.size.height;
fromViewController.view.frame = newFrame;
}
} completion:^(BOOL finished) {
[transitionContext completeTransition:finished];
}];
}
关于iOS 7 - 带有 UIViewcontrollerAnimatedTransitioning 的模态弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24990949/
我想在navigationController的推送和弹出上制作一个过渡动画。但它的工作原理真的很奇怪。就像 1/5 倍一样,fromViewController 会淡出,但 toViewContro
做一个 simpel 转换但没有被调用我没有得到我在这里错过的东西。任何人都可以帮助我。没有收到任何错误或警告。 动画类-: import UIKit class CustomPresentAnima
我正在尝试使用 Pop-in 效果在 UIViewControllers 之间设置动画转换。 在我的 animateTransition(using transitionContext:) 函数中:
我已经在这里工作了几个小时,无法理解我做错了什么。我已经按照我之前的 Swift: Problems with custom UIView.transition? 中描述的 UITabBarContr
我已经创建了一个过渡并且它工作正常,除了我在模拟器中有时会出现黑角。此外,在 iPad Pro 中,如果我以全分辨率运行模拟器,我会得到一个完全黑屏。调整后的分辨率工作正常。你知道可能是什么问题吗?我
我试图使用 Swift 协议(protocol)提供 UIViewControllerAnimatedTransitioning 的通用实现,但每当我有一个符合该协议(protocol)的对象时,我都
我有一个 segue,它是通过一个按钮触发的,该按钮在当前上下文中模态显示另一个 View Controller 。我正在使用自定义类来自定义转换,它是这样的: class ShowAnimator:
在搜索如何在从一个 Controller 过渡到另一个 Controller 时执行自定义动画时,我发现了一些有关 UIViewControllerAnimatedTransitioning 的信息。
我已经为全屏显示的 Controller 实现了交互式关闭动画。 问题是每当我尝试关闭它时,状态栏都会出现 全屏 Controller 的 - (BOOL)prefersStatusBarHidden
我已经在 navigationController 上成功实现了 UIViewControllerAnimatedTransitioning,并且在 iOS 7 上有一个很好的自定义转换。 现在的问题
我在ViewController A中实现了这个方法 - (BOOL)prefersStatusBarHidden { return NO; } 我在 ViewController B 中实现了该
我正在尝试制作自定义演示动画,但 VC 是一个 MPMoviePlayerViewController。我正在学习本教程: 当我呈现 MPMoviePlayerViewController 时,一切正
自定义过渡对我来说相当陌生。我不得不将它们合并到我工作的最后一个项目中,并最终使用 UIViewControllerAnimatedTransitioning 协议(protocol)和自定义 seg
所以我开始着手创建自定义插入/弹出转换,第一次插入转换时一切正常,但是当我尝试插入另一个 View Controller 时,我根本看不到任何动画。 Here is a sample project
我试图在推送 UIViewController 时进行简单的动画转换,但似乎我遗漏了一些东西。 我将 subview 的快照从 fromViewController 动画化到 toViewContro
我正在尝试使用 UIViewcontrollerAnimatedTransitioning 为 PopUp ViewController 呈现动画。我已经创建了一个从 TableViewCell 到我
我刚刚花了最后几个小时来追踪一个恰好位于转换驱动程序对象中的错误,多次调用 interruptibleAnimator 方法,其中: 一个 UIViewPropertyAnimator 完成闭包包含对
将 View Controller 推送到 UINavigationController 时如何获得自定义转换 (iOS7)?我尝试在 UINavigationController 和我正在推送的 C
我今天刚用 Swift4 升级到 XCode9。我发现我的 UIViewControllerAnimatedTransitioning 不再按预期工作。这个动画的效果是fromView会缩小到0.95
我正在使用一些 UIViewController包含在 UINavigationController 中. 一个人会收到一个推送 segue来自UIButton在 storyboard 上, 然后使用
我是一名优秀的程序员,十分优秀!