Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 5后退按钮大小_Ios_Ios5_Uinavigationitem_Uiappearance - Fatal编程技术网

iOS 5后退按钮大小

iOS 5后退按钮大小,ios,ios5,uinavigationitem,uiappearance,Ios,Ios5,Uinavigationitem,Uiappearance,我使用iOS5来使用自定义导航栏后退按钮,如图所示。与我发现的其他方法不同,这是最好的方法,因为它保留了默认的后退按钮动画和行为 唯一的问题是,我无法更改其大小或将其设置为不剪裁子视图。下面是正在发生的事情: A为预期行为,B为默认样式,C为剪裁结果 不幸的是,这并不像将uibarbuttonite设置为clipstobunds=NO那么容易 有人知道如何解决这个问题吗?谢谢 正如您所发现的,UIAppearance代理不允许您调整按钮本身的尺寸:文档中给出了UIBarButtonItem支持

我使用iOS5来使用自定义导航栏后退按钮,如图所示。与我发现的其他方法不同,这是最好的方法,因为它保留了默认的后退按钮动画和行为

唯一的问题是,我无法更改其大小或将其设置为不剪裁子视图。下面是正在发生的事情:

A为预期行为,B为默认样式,C为剪裁结果

不幸的是,这并不像将uibarbuttonite设置为clipstobunds=NO那么容易


有人知道如何解决这个问题吗?谢谢

正如您所发现的,
UIAppearance
代理不允许您调整按钮本身的尺寸:文档中给出了
UIBarButtonItem
支持的外观方法列表,虽然它包括标题标签本身的度量,但按钮是禁止使用的

值得一提的是,按钮本身的可触摸区域实际上是44分(88像素,如果你在视网膜上的话)高,只是按钮图形比这个小

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

更新:我刚刚发现,如果你把后退按钮放在周围,事实上,你可以设置它的动画,让它以类似于标准后退按钮的方式滑动。在下面的代码中,
self.backButton
是您在
initWithCustomView
UIBarButtonItem
方法中应该使用的
ui按钮

- (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
委托,仅在导航控制器弹出时触发它。当按下控制器时,它似乎确实会移动按钮,尽管我只在模拟器上测试过它。

我最终为我在导航控制器中使用的每个VC使用了一个自定义视图控制器类

OEViewController.h

#import <UIKit/UIKit.h>
#import "OEBarButtonItem.h"

@interface OEViewController : UIViewController

@property (nonatomic, retain) UIButton *backButton;
@property (atomic) BOOL pushed;

- (void)pushViewController:(UIViewController*)vc;

@end
与使用UIAppearance相比,使用iOS 4.0+具有额外的好处


感谢@lxt的帮助

您是否尝试过UIBarButtonItem.superview.clipsToBounds=否?(或superview.superview…),因为导航栏的大小不应超过其原来的大小。所以你要尝试的任何东西都是“黑客”。如果这是一种黑客行为,那么这就是“标准”方法:-)你所推荐的是不可能的,因为
uibarbuttonite
不是从
UIView
继承的。但是,我已尝试设置self.navigationController.navigationItem.backbarbuttoneim.customView.clipsToBounds=NO
self.navigationItem.backBarButtonItem.customView.clipsToBounds=否。我想你的意思是,
uibarbuttonim
不打算变大,因为我没有接触导航条本身。是的,你是对的!我通常的意思是遍历视图层次并找出哪一个剪辑。此外,您可能需要以不同的方式处理iOS<5和iOS>=5。实际上,我的意思是导航栏并不意味着要更大,因为导航栏上的项目不受限制,导航栏是限制它们的地方。它有硬编码的填充,剩余的是按钮的空间。感谢您确认我对
ui外观的怀疑,@lxt。不幸的是,通过设置自定义的
leftBarButtonItem
,我丢失了
backBarButtonItem
动画(水平滑动),并且由于
UIBarButtonItem
没有继承自
UIView
,我自己无法对其进行动画制作。请尝试我刚刚发布的代码,可能会对动画制作有所帮助。似乎对我有用。
#import "OEViewController.h"

#define ANIMATION_DURATION 0.33

@implementation OEViewController
@synthesize backButton, pushed;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    pushed=YES;
    self.navigationItem.hidesBackButton = YES;

    backButton = [OEBarButtonItem backButtonWithTitle:[(UIViewController*)[self.navigationController.viewControllers objectAtIndex:[self.navigationController.viewControllers count]-2] title]];

    [backButton addTarget:self action:@selector(backButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (pushed) {
        self.backButton.frame = CGRectMake(self.backButton.frame.origin.x+100, 
                                           self.backButton.frame.origin.y+6, 
                                           self.backButton.frame.size.width, 
                                           self.backButton.frame.size.height);
        [UIView animateWithDuration:ANIMATION_DURATION 
                         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);
                         }];
        pushed=NO;
    } else {
        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);
        [UIView animateWithDuration:ANIMATION_DURATION 
                         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);
                         }];
    }
}

- (void)backButtonPressed:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
    [UIView animateWithDuration:ANIMATION_DURATION 
                     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);
                     }];
}

- (void)pushViewController:(UIViewController*)vc {
    [self.navigationController pushViewController:vc animated:YES];
    [UIView animateWithDuration:ANIMATION_DURATION 
                     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);
                     }];
}

@end