sto*_*roj 38 cocoa-touch ios ios7 xcode5
我想使用自定义后退按钮.在iOS 6中,一切都很完美,但iOS 7很奇怪.
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"back_button_normal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.0, 0, 12.0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
首先,它没有iOS 7箭头,也没有背景图像.
(俄语语言环境)

然后,如果按下按钮,则会出现背景图像.此外,我为UIControlStateHighlighted状态设置了背景图像,当您按住按钮时,按下突出显示的图像也会出现.按下任何后退按钮后,所有后退按钮都有背景图像.

但!如果您提供模态视图控制器,将其关闭,然后按任何视图控制器 - iOS 7每个后退按钮都会出现箭头.
我用的是DP5.这是UIKit的错误吗?
PS我还试图手动创建后退按钮,使用UIBarButtonItem,设置背景图像,然后self.navigationItem.backBarButtonItem = barButtonItem;没有帮助.然后我尝试将背景图像设置为禁用状态并更改我的栏按钮项的启用属性,也没有帮助.

B.S*_*.S. 50
这不是一个bug,这Back button在iOS 7中看起来如何.例如:
您可能应该为您的应用程序使用新概念,而不是在iOS 7中为后退按钮设置背景图像.
如果您仍然希望您的后退按钮与iOS6中的相同,那么您应该手动创建这些后退按钮:
- (void)loadView
{
[super loadView];
UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 60.0f, 30.0f)];
UIImage *backImage = [[UIImage imageNamed:@"back_button_normal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.0f, 0, 12.0f)];
[backButton setBackgroundImage:backImage forState:UIControlStateNormal];
[backButton setTitle:@"Back" forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backButtonItem;
}
-(void) popBack {
[self.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
编辑:不打破Swipe Gesture(这是一个来源)
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
Run Code Online (Sandbox Code Playgroud)
kol*_*hiy 22
第一次推送时未出现的自定义背景图像已在iOS 7 GM中修复.
要隐藏标准后退指示符,请使用此代码:
if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) { // iOS 7
[navigationBarAppearance setBackIndicatorImage:[UIImage imageNamed:@"transparent_1px"]];
[navigationBarAppearance setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"transparent_1px"]];
}
Run Code Online (Sandbox Code Playgroud)
Car*_*erg 13
据我所知,最初没有出现的自定义背景图像在iOS7 GM或final中没有修复.我看到了同样的问题.它似乎确实是一个苹果虫; Apple使用的私有视图在初始显示时只需要setNeedsDisplay调用.对它做任何导致该调用的事情应该修复它 - 比如按下它(这可能会改变内部状态,因此它自己调用setNeedsDisplay),或者带来一个模态(这可能会强制重新显示下一个整个视图层次结构) viewWillAppear:call).
使用leftBarItems也可以工作,但这可能会导致现有代码的许多维护问题(某些屏幕可能有自己的左项,例如,当设置回nil时,它们会恢复原始的后退项目).
如上所述,理想情况下,您可以在iOS7上更改为无边框外观,这意味着该错误并不明显(因为没有背景图像).但是对于某些iOS6/iOS7转换情况,这可能很困难(很多屏幕,和/或需要支持旧iOS版本一段时间而且太难以实现两个外观,并且没有其他情况它看起来不太好变化).如果是这种情况,以下补丁应该有效:
#import <objc/runtime.h>
@implementation UINavigationBar (BackButtonDisplayFix)
+ (void)load
{
if ([UIDevice currentDevice].systemVersion.intValue >= 7)
{
/*
* We first try to simply add an override version of didAddSubview: to the class. If it
* fails, that means that the class already has its own override implementation of the method
* (which we are expecting in this case), so use a method-swap version instead.
*/
Method didAddMethod = class_getInstanceMethod(self, @selector(_displaybugfixsuper_didAddSubview:));
if (!class_addMethod(self, @selector(didAddSubview:),
method_getImplementation(didAddMethod),
method_getTypeEncoding(didAddMethod)))
{
Method existMethod = class_getInstanceMethod(self, @selector(didAddSubview:));
Method replacement = class_getInstanceMethod(self, @selector(_displaybugfix_didAddSubview:));
method_exchangeImplementations(existMethod, replacement);
}
}
}
- (void)_displaybugfixsuper_didAddSubview:(UIView *)subview
{
[super didAddSubview:subview];
[subview setNeedsDisplay];
}
- (void)_displaybugfix_didAddSubview:(UIView *)subview
{
[self _displaybugfix_didAddSubview:subview]; // calls the existing method
[subview setNeedsDisplay];
}
@end
Run Code Online (Sandbox Code Playgroud)
注意:UINavigationBar当前有一个覆盖有问题的方法,所以我希望使用method_exchangeImplementations样式.我刚刚添加其他东西以确保安全,以防Apple改变他们的代码.我们可能自己没有边界,但我确实发现这种方法可以作为一种选择(直到更彻底的UI提升),至少.
附加说明:此错误似乎在iOS 7.1中得到修复.因此,如果运行> = 7.0和<7.1,则可以将补丁条件化为仅安装方法.
小智 6
有一个更好的解决方案,不涉及方法调配.
您需要在应用程序的某处添加UINavigationViewControllerDelegate方法.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
dispatch_async(dispatch_get_main_queue(), ^{
[[navigationController.navigationBar subviews] makeObjectsPerformSelector:@selector(setNeedsDisplay)];
});
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
57011 次 |
| 最近记录: |