cocoa - 当警报 View 关闭时,右侧导航栏按钮会移动

标签 cocoa ios7 uiimage uialertview rightbarbuttonitem

我正在将 iOS 6 应用程序调整为 iOS 7,但遇到了一个奇怪的“错误”。在屏幕中,有一个 rightBarButtonItem,其中显示了一个简单的图像。但是,如果应用程序显示警报 View ,则当我点击警报 View 的“确定”按钮(此警报中的唯一按钮)时,图像会向下移动(50 像素左右)。没有任何操作链接到此警报 View ,它只是提供信息。

此外,如果我更改按钮的图像(setImage),该图像将出现不合适的位置。

最佳答案

好吧,我终于找到了解决方案:

我有一个带有 UIBarButtonItemStylePlainUIBarButtonItem 以及在 UIBarButtonItem 上使用 setImage 设置的图像。

为了解决这个问题,我创建了一个带有图像的 UIButton (使用 CGRectMake 设置其框架),然后创建了 UIBarButtonIteminitWithCustomView 并使用 UIButton 作为 CustomView。这样图像始终位于应有的位置。

编辑:

UIButton* aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(0.0, 40.0, 30.0, 30.0);
[aButton setBackgroundImage:[UIImage imageNamed:@"anImage.png"] forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(aFunction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *anUIBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:aButton]; 
self.navigationItem.rightBarButtonItem = anUIBarButtonItem;

关于cocoa - 当警报 View 关闭时,右侧导航栏按钮会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21697868/

相关文章:

macos - 无法使用 GCD 函数调用进行编译

iphone - IOS模式segue返回黑屏

ios - 完成转换时的 io7 导航检查

iOS 7 小进度条可以改成 iOS6 风格吗?

ios - ImageContext 返回扭曲的图像

ios - 64 位 RGBA UIImage? 64 位的 CGBitmapInfo

cocoa - 卸载驱动器/卷而不弹出

cocoa - 存储文件以供所有用户访问的位置

iphone - 所有的类方法都返回一个自动释放的对象吗?

ios - 在 iPhone 应用程序中保存图片