gpt4 book ai didi

ios - 如何使用 Storyboard停止 UINavigationBar 默认后退按钮动画?

转载 作者:行者123 更新时间:2023-11-29 12:39:38 27 4
gpt4 key购买 nike

我在我的应用程序中使用 storyboard ,我必须在没有动画的情况下导航到另一个 View Controller 。我使用自定义 segue 成功地做到了。但是当我回到以前的 View Controller 时然后通过使用导航栏默认后退按钮然后它在后退时设置动画。所以前进它不是动画而后退它是动画。我想停止后退按钮的默认动画。

自定义海格

//PushNoAnimationSegue.h

@interface PushNoAnimationSegue : UIStoryboardSegue

@end

//PushNoAnimationSegue.m

@implementation PushNoAnimationSegue

-(void) perform{
[[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
}

@end

使用这段代码,我成功地进入了下一个没有动画的 View Controller ,因为 -(void) perform 在前进方向上被自动调用。当我回来时它没有被调用。所以请建议如果实现有任何问题,或者我应该采用其他方法。

最佳答案

希望对你有帮助

1.导航栏自定义按钮

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(x,y,width,height)];
[btn setImage:[UIImage imageNamed:@"some_image.png"] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem =backButtonItem;

然后

void popViewController()
{
[self.navigationController popViewControllerAnimated:NO];
}

关于ios - 如何使用 Storyboard停止 UINavigationBar 默认后退按钮动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25306062/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com