iOS 5后退按钮大小 [英] iOS 5 Back Button Size

查看:86
本文介绍了iOS 5后退按钮大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 5 UIAppearance协议使用自定义导航栏后退按钮,如图所示此处。与我发现的其他方法不同,这个方法是最好的,因为它保留了默认的后退按钮动画和行为。

I'm using the iOS 5 UIAppearance protocol to use a custom navigation bar back button as seen here. Unlike other methods I've found, this one is the best since it preserves the default back button animations and behaviours.

唯一的问题是我无法改变它尺寸或将其设置为不剪辑子视图。以下是发生的事情:

The only problem is that I can't change its size or set it to not clip subviews. Here's what's happening:

A是预期的行为,B是默认样式,C是剪切结果。

A is intended behaviour, B is default style, C is the clipped result.

不幸的是,它并不像将UIBarButtonItem设置为clipsToBounds = NO。

Unfortunately, it's not as easy as setting UIBarButtonItem to clipsToBounds=NO.

有谁知道如何解决这个问题?谢谢!

Does anyone know how to solve this issue? Thanks!

推荐答案

正如您所发现的, UIAppearance proxies won' t让你调整按钮本身的尺寸:文档中给出了 UIBarButtonItem 支持的外观方法列表,同时它包含标题标签本身的指标按钮是禁区。

As you've discovered, UIAppearance proxies won't let you adjust the dimensions of the button itself: the list of supported appearance methods for UIBarButtonItem is given in the documentation, and whilst it includes metrics for the title label itself the button is off-limits.

对于它的价值,按钮本身实际上是44磅(88像素,如果你在视网膜中)在可触摸区域方面很高,它只是按钮图形小于那个。

For what it's worth, the button itself is actually 44 pts (88 pixels, if you're in retina) high in terms of touchable area, it's just the button graphic is smaller than that.

如果你已经死定了相当于3磅高度的差异那么最好的选择可能是创建自己的自定义按钮并使用 UINavigationItem setLeftBarButtonItem 方法。正如您所指出的,您将需要实现一个附加到该按钮的简短方法,该方法实现 popNavigationController 以确保保持正确的行为。

If you're dead set on what amounts to a 3 pt difference in height then the best option is probably going to be to create your own custom button and use the UINavigationItem setLeftBarButtonItem method. As you point out, you're going to need to implement a short method attached to that button that implements popNavigationController to ensure the correct behavior remains.

更新:我刚刚发现,如果你保留你的后退按钮,你可以实际上动画它,使它以类似于标准的方式滑动返回键。在下面的代码中 self.backButton 是您在 initWithCustomView <中使用的 UIButton / code> UIBarButtonItem 方法。

Update: I've just found out that if you keep your back button around you can, in fact, animate it to have it slide in a similar fashion to a standard back button. In the code below self.backButton is the UIButton you would have used in your initWithCustomView UIBarButtonItem method.

- (void)viewWillDisappear:(BOOL)animated {
    [UIView animateWithDuration:0.3 
                     animations:^{
                         self.backButton.frame = CGRectMake(self.backButton.frame.origin.x+100, 
                                                            self.backButton.frame.origin.y, 
                                                            self.backButton.frame.size.width, 
                                                            self.backButton.frame.size.height);
                     }];
}

...只要视图控制器消失(即弹出时),这将触发推送),但您可以挂钩到 UINavigationController 委托,只在弹出导航控制器时触发它。当按下控制器时,它似乎肯定会移动按钮,虽然我只是在模拟器上测试过它。

...this will trigger whenever the view controller disappears (ie, when popped and pushed), but you could hook into the UINavigationController delegate to only trigger it when the nav controller is popped instead. It definitely seems to move the button when controller is pushed, although I've only tested it on the simulator.

这篇关于iOS 5后退按钮大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆