作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想通过源场景中的按钮来切换目标场景。我还想控制 View Controller 之间的过渡动画(我想从右到左为 2 个 View 设置动画)。是否可以通过替换segue来做到这一点?我尝试了替换转场和推送转场,但转场没有发生任何建议我应该如何继续?谢谢!
最佳答案
我发现replace segue 和push segue 具有误导性,因为replace 似乎可用于主细节 Controller ,而push segue 仅适用于导航 Controller 。在这种情况下,我需要实现自定义转场。您需要继承 UIStoryboardSegue 并覆盖执行 segue。
这是我的代码的一个例子:
-(void)perform{
UIView *sourceView = [[self sourceViewController] view];
UIView *destinationView = [[self destinationViewController] view];
UIImageView *sourceImageView;
sourceImageView = [[UIImageView alloc]
initWithImage:[sourceView pw_imageSnapshot]];
// force the destination to be in landscape before screenshot
destinationView.frame = CGRectMake(0, 0, 1024, 748);
CGRect originalFrame = destinationView.frame;
CGRect offsetFrame = CGRectOffset(originalFrame, originalFrame.size.width, 0);
UIImageView *destinationImageView;
destinationImageView = [[UIImageView alloc]
initWithImage:[destinationView pw_imageSnapshot]];
destinationImageView.frame = offsetFrame;
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];
[destinationView addSubview:sourceImageView];
[destinationView addSubview:destinationImageView];
void (^animations)(void) = ^ {
[destinationImageView setFrame:originalFrame];
};
void (^completion)(BOOL) = ^(BOOL finished) {
if (finished) {
[sourceImageView removeFromSuperview];
[destinationImageView removeFromSuperview];
}
};
[UIView animateWithDuration:kAnimationDuration delay:.0 options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion];
}
关于ipad - 您如何从 Storyboard中的 UIButton 执行自定义转场(模态转场),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9466231/
我是一名优秀的程序员,十分优秀!