在没有动画的情况下在xcode中推送segue
我在xcode中使用普通的故事板和推式分段,但我希望分段只出现在下一个视图中,而不是滑动到下一个视图中(如使用选项卡栏时,下一个视图刚刚出现) 有没有一种简单的方法可以让普通的推送序列“出现”而不是“滑动”,而不需要添加自定义序列在没有动画的情况下在xcode中推送segue,xcode,animation,segue,Xcode,Animation,Segue,我在xcode中使用普通的故事板和推式分段,但我希望分段只出现在下一个视图中,而不是滑动到下一个视图中(如使用选项卡栏时,下一个视图刚刚出现) 有没有一种简单的方法可以让普通的推送序列“出现”而不是“滑动”,而不需要添加自定义序列 一切都很正常,我只想删除视图之间的幻灯片动画。我现在已使用以下代码成功完成此操作: CreditsViewController *creditspage = [self.storyboard instantiateViewControllerWithIdentifie
一切都很正常,我只想删除视图之间的幻灯片动画。我现在已使用以下代码成功完成此操作:
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];
希望这对其他人有帮助 我可以通过创建自定义segue(基于)来实现这一点
PushNoAnimationSegue
(或您决定调用它的任何名称)#import <UIKit/UIKit.h>
/*
Move to the next screen without an animation.
*/
@interface PushNoAnimationSegue : UIStoryboardSegue
@end
伊恩的答案很有用 如果有人需要,这里有一个快速版本的Segue: 针对SWIFT 5更新,2020年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)
}
}
下面是一个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)
}
}
对于任何使用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类。您可以在iOS 9的Interface Builder中取消选中“动画”
只需在Swift中的
UINavigationController.pushViewController上设置animated
false
self.navigationController!.pushViewController(viewController, animated: false)
对我来说,最简单的方法是:
UIView.performWithoutAnimation {
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
可从iOS 7.0获得使用Swift3回答-
对于“推送”序列:
对于“模态”序列:
我使用的是visualstudio w/Xamarin,而设计师在dtochetto的回答中没有提供“Animates”复选标记
请注意,XCode设计器将对.storyboard文件中的segue元素应用以下属性:animates=“NO”
我手动编辑了.storyboard文件,并在segue元素中添加了animates=“NO”,这对我来说很有效
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 id="1234" destination="ZB0-vP-ctU" kind="modal" modalTransitionStyle="crossDissolve" animates="NO" identifier="screen1ToScreen2"/>
无动画推送: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,请将viewcontroller中的isAnimationRequired设置为false,并在调用self.performsgue后将其设置为true。祝你好运
DispatchQueue.main.async {
self.isAnimationRequired = false
self.performSegue(withIdentifier: "showAllOrders", sender: self);
self.isAnimationRequired = true
}
我刚刚尝试将推送序列更改为模式序列,因为这样可以删除动画,但我有一个带有顶部工具栏的tableview,将该序列设置为模式将删除该顶部栏,我找不到任何方法将顶部栏添加回去!因此,我需要一个解决方案,它不会设置过渡动画,但不会破坏我的tableview。你可以将其添加到UIButton或其他任何操作中。如果要跳转到没有动画的新视图控制器,可以使用:-void(yourUIButtonAction){CreditsViewController*creditspage=[self.storyboard InstanceEviewController WithiIdentifier:@“Credits”];[self.navigationController pushViewController:creditspage animated:no];}这甚至没有回答问题。你没有在这里使用segue!谢谢你的评论和意见。最好的答案。有什么想法可以让背部动画达到同样的效果吗?很有魅力。这也是使用故事板分段的“正确”方法。是否有人为上述答案停止了反向动画。不是解决方案,自定义分段在整个布局上呈现,就像模式推送一样,而原始推送分段尊重window.frame navigationController tabBarController等。。。如何将segue配置为类似于推送segue而不是模式segue?或1.000.000美元的问题,当使用故事板配置常规序列时,如何指定animations=NO此代码从@zaviéanswer复制,不添加任何内容,但事实上更糟糕的是:没有检查可选项。这与@zavié的答案不同,因为它显示了如何在没有动画的情况下以模态方式呈现ViewController。很高兴将其作为参考,因为它与问题有点相关。可能是因为Swift版本,我需要“as!”而不是“as”在你使用它们的两个地方。嗯,可能在Swift 1.2中?我在Xcode 7 Beta1中使用Swift 2.0进行了检查,它在编译时没有任何警告。这是原始问题的答案!其他答案显示了如何在objc/swift代码中实现这一点,而dtochetto只使用Xcode(如原问题中所要求的)。但是对于展开序列,它似乎不起作用。这是最好、最快的解决方案,不幸的是,这在iOS 8上不起作用。@DanielT。也许,你可以在情节提要上拖动2段,一段有动画,另一段没有动画。为它们指定不同的标识符
名称。请注意,XCode只是向.storyboard文件中的segue元素添加了一个属性。如果您正在使用visual studio,并且复选标记在设计器中不可用,则可以手动编辑.storyboard文件并将animates=“NO”添加到您关心的序列中。如果使用自适应序列,我相信虽然PerformOutAnimation设置为禁用动画,但在执行序列之前,如果序列已禁用,则会再次启用动画“动画”已选中。执行后,如果以前禁用过,则会再次禁用它们。但您可以通过创建UIStoryboardSegue子类并在执行前再次禁用动画来解决此问题(例如,使用构造函数检查动画是否已禁用,并将其存储在属性中).不知道为什么这被否决了.对我来说非常有效!
<segue id="1234" destination="ZB0-vP-ctU" kind="modal" modalTransitionStyle="crossDissolve" animates="NO" identifier="screen1ToScreen2"/>
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)
}
}
}
DispatchQueue.main.async {
self.isAnimationRequired = false
self.performSegue(withIdentifier: "showAllOrders", sender: self);
self.isAnimationRequired = true
}