ios - 不同方向的 UINavigationBar titleView

标签 ios uinavigationbar uinavigationitem titleview

当方向改变时调整 UINavigationBar titleview 内容图像大小的最佳方法是什么。 我有一张图像高度为 44 像素,另一张图像高度为 32 像素,在旋转 View 后,我更改标题 View 并设置新的 ImageView 。但也许还有另一种方法可以通过 autoresizingmask 或其他一些技巧来实现某些结果?

最佳答案

autoresizingMask 可以在设备旋转时修改 View 框架的大小,但如果您想在旋转时在两个不同的图像之间切换,则必须在 willAnimateRotationToInterfaceOrientation:duration:< 中以编程方式执行此操作

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    [super willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration];

    if (interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation == UIDeviceOrientationLandscapeLeft) {        
        // landscape
        [imageView setImage:landscapeImage]; 
    } else {
        // portrait
        [imageView setImage:portraitImage]; 
    }
}

关于ios - 不同方向的 UINavigationBar titleView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335049/

相关文章:

ios - UINavigationItem 标题 View 的框架

ios - 使用导航 Controller 的优点

ios - 更改导航栏的 alpha 值以便底层对象可见

ios - 尝试添加 UINavigationBar 按钮时发生崩溃

ios - 在for循环中传递数据时,MagicalRecord将保存null

ios - RestKit postObject 方法中的 post 对象和它返回的 RKMappingResult 是什么关系?

ios - 在 Scrollview ios 中使用 textview 时避免多次滚动

ios - iOS Enterprise Build发行版

objective-c - 隐藏 UINavigationBar 时的自定义动画

ios - 如何在 iOS 应用程序中手动设置 "Back"目的地