我在 xcode 中使用普通的故事板和推送转场,但我希望转场只出现在下一个视图中,而不是滑动下一个视图(就像您使用标签栏并且下一个视图刚刚出现时一样)。
有没有一种简单的方法可以让普通的推送转场只是“出现”而不是“滑动”,而不需要添加自定义转场?
一切都很好,我只想删除视图之间的幻灯片动画。
我可以通过创建自定义 segue(基于此链接)来做到这一点。
PushNoAnimationSegue
(或您决定调用的任何名称)。import UIKit
/*
Move to the next screen without an animation.
*/
class PushNoAnimationSegue: UIStoryboardSegue {
override func perform() {
self.source.navigationController?.pushViewController(self.destination, animated: false)
}
}
PushNoAnimationSegue.h
#import <UIKit/UIKit.h>
/*
Move to the next screen without an animation.
*/
@interface PushNoAnimationSegue : UIStoryboardSegue
@end
PushNoAnimationSegue.m
#import "PushNoAnimationSegue.h"
@implementation PushNoAnimationSegue
- (void)perform {
[self.sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO];
}
@end
伊恩的回答效果很好!
如果有人需要,这是 Segue 的 Swift 版本:
为 2020 年 5 月的 SWIFT 5 更新
PushNoAnimationSegue.swift
import UIKit
/// Move to the next screen without an animation
class PushNoAnimationSegue: UIStoryboardSegue {
override func perform() {
if let navigation = source.navigationController {
navigation.pushViewController(destination as UIViewController, animated: false)
}
}
我现在已经设法使用以下代码做到这一点:
CreditsViewController *creditspage = [self.storyboard instantiateViewControllerWithIdentifier:@"Credits"];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:creditspage animated:NO];
[UIView commitAnimations];
希望这对其他人有帮助!
这是适用于模态呈现不带动画的 ViewController 的 Swift 版本:
import UIKit
/// Present the next screen without an animation.
class ModalNoAnimationSegue: UIStoryboardSegue {
override func perform() {
self.sourceViewController.presentViewController(
self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
}
使用Swift3回答-
对于“推动”转场:
class PushNoAnimationSegue: UIStoryboardSegue
{
override func perform()
{
source.navigationController?.pushViewController(destination, animated: false)
}
}
对于“模态”转场:
class ModalNoAnimationSegue: UIStoryboardSegue
{
override func perform() {
self.source.present(destination, animated: false, completion: nil)
}
}
对于使用 Xamarin iOS 的任何人,您的自定义 segue 类需要如下所示:
[Register ("PushNoAnimationSegue")]
public class PushNoAnimationSegue : UIStoryboardSegue
{
public PushNoAnimationSegue(IntPtr handle) : base (handle)
{
}
public override void Perform ()
{
SourceViewController.NavigationController.PushViewController (DestinationViewController, false);
}
}
不要忘记您仍然需要在故事板中设置自定义 segue 并将类设置为 PushNoAnimationSegue 类。
只需在Swift 中设置animated
falseUINavigationController.pushViewController
self.navigationController!.pushViewController(viewController, animated: false)
对我来说,最简单的方法是:
UIView.performWithoutAnimation {
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
适用于 iOS 7.0
PUSH without ANIMATION : Swift 这对我有用。
import ObjectiveC
private var AssociatedObjectHandle: UInt8 = 0
extension UIViewController {
var isAnimationRequired:Bool {
get {
return (objc_getAssociatedObject(self, &AssociatedObjectHandle) as? Bool) ?? true
}
set {
objc_setAssociatedObject(self, &AssociatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
-------------------- SilencePushSegue --------------------
class SilencePushSegue: UIStoryboardSegue {
override func perform() {
if self.source.isAnimationRequired == false {
self.source.navigationController?.pushViewController(self.destination, animated: false)
}else{
self.source.navigationController?.pushViewController(self.destination, animated: true)
}
}
}
用法:从情节提要中设置 segue 类,如图所示。当你想在没有动画的情况下推送 segue 并在调用 self.performSegue 后将其设置回 true 时,将 viewcontroller 中的 isAnimationRequired 设置为 false,从你想调用 performSegue 的位置。祝你好运......
DispatchQueue.main.async {
self.isAnimationRequired = false
self.performSegue(withIdentifier: "showAllOrders", sender: self);
self.isAnimationRequired = true
}
我正在使用带有 Xamarin 的 Visual Studio,并且设计器没有在 dtochetto 的答案中提供“动画”复选标记。
请注意,XCode 设计器会将以下属性应用于 .storyboard 文件中的 segue 元素: animates="NO"
我手动编辑了 .storyboard 文件并将 animates="NO" 添加到 segue 元素,它对我有用。
例子:
<segue id="1234" destination="ZB0-vP-ctU" kind="modal" modalTransitionStyle="crossDissolve" animates="NO" identifier="screen1ToScreen2"/>