iOS 7 - 带有 UIViewcontrollerAnimatedTransitioning 的模态弹出窗口
<p><p>我正在尝试使用 UIViewcontrollerAnimatedTransitioning 呈现带有动画的 PopUp ViewController。我已经创建了一个从 TableViewCell 到我的 Viewcontroller 的 Modal Segue</p>
<p>在 PopupPresentAnimationController(实现 UIViewcontrollerAnimatedTransitioning)中我有</p>
<pre><code>-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = ;
UIViewController *toViewController = ;
;
toViewController.view.frame = fromViewController.view.frame;
;
;
NSTimeInterval duration = ;
[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;
;
}];
}
</code></pre>
<p>PopUpViewController 的背景为黑色,不透明度为 50%,当它出现所有“工作”但动画结束后,屏幕变黑。</p>
<p><strong>更新 1:</strong></p>
<pre><code>UIViewController *fromViewController =;
UIViewController *toViewController = ;
UIView *container = ;
CGRect initialFrame = toViewController.view.frame;
initialFrame.origin.y = toViewController.view.frame.size.height;
toViewController.view.frame = initialFrame;
;
NSTimeInterval duration = ;
[UIView animateWithDuration:duration delay:0 options:0 animations:^{
CGRect newFrame = toViewController.view.frame;
newFrame.origin.y = 0;
toViewController.view.frame = newFrame;
} completion:^(BOOL finished) {
;
}];
</code></pre>
<p><strong>更新 2</strong>
在 prepareForSegue 我添加了以下行</p>
<pre><code>controller.modalPresentationStyle = UIModalPresentationCustom; // controller is the destination
</code></pre>
<p>有了这条线,黑色就不再是黑色了!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您遇到的问题是您将 <code>toViewController</code> 添加到 <code>fromViewController</code>。当动画结束时,<code>toViewController</code> 被移除,而你的 <code>fromViewController</code> 也被移除。处理这个问题的正确方法是使用上下文提供的容器 View :</p>
<pre><code>UIView *container = ;
</code></pre>
<p>这是一个如何进行弹出转换的示例:</p>
<pre><code>-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromViewController = ;
UIViewController *toViewController = ;
UIView *container = ;
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;
;
}
[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) {
;
}];
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS 7 - 带有 UIViewcontrollerAnimatedTransitioning 的模态弹出窗口,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24990949/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24990949/
</a>
</p>
页:
[1]