ios7关于自定义导航条UIBarButtonItem偏移的问题
ios7里导航条按钮会往左或右偏移几个像素,参考这篇文章使用该方法-(UIEdgeInsets)alignmentRectInsets{UIEdgeInsetsinset...
ios7里导航条按钮会往左或右偏移几个像素,参考这篇文章 使用该方法- (UIEdgeInsets)alignmentRectInsets { UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0,0); if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { if (self.isLeft) { insets = UIEdgeInsetsMake(0, 5.0f, 0, 0); } else { // IF_ITS_A_RIGHT_BUTTON insets = UIEdgeInsetsMake(0, 0, 0, 5.0f); } } return insets;}- (UIEdgeInsets)alignmentRectInsets { UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0,0); if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { if (self.isLeft) { insets = UIEdgeInsetsMake(0, 5.0f, 0, 0); } else{ // IF_ITS_A_RIGHT_BUTTON insets = UIEdgeInsetsMake(0, 0, 0, 5.0f); } } return insets;}可以调整到正确的位置,但是切换页面的时候没办法直接切换,会有先显示旧的位置然后才会显示调整后的位置的动作,各位有何办法解决吗?
展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
你应该设置imageEdgeInsets self.view.backgroundColor = [UIColor blueColor]; UIButton* btn = [BarItemButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 45, 40); [btn setImage:[UIImage imageNamed:@"come_back.png"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -13, 0, 0); [btn addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];如果你实现了alignmentRectInsets也不是不行,但是问题在于你pushViewController时候启动了动画,而alignmentRectInsets也会有动画效果 查看原帖>>
采纳哦
采纳哦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询