gpt4 book ai didi

ios - 导航栏中的 UINavigationItem 位置在方向上没有改变

转载 作者:行者123 更新时间:2023-11-28 09:14:40 24 4
gpt4 key购买 nike

我在导航栏的右侧导航项上添加了自定义图像。但是当我旋转设备时,右按钮项目会停留在纵向位置。

肖像

enter image description here

风景

enter image description here

如您所见,当从纵向更改为横向时,菜单图标会固定在其原始位置。

代码

    let menuImage = UIImage(named: "right_menu_icon.png")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)


var right_menu_button = CBarButton.buttonWithType(UIButtonType.Custom) as CBarButton
right_menu_button.setBackgroundImage(menuImage, forState: UIControlState.Normal)
right_menu_button.setBackgroundImage(UIImage(named:"right_menu_icon_highlight.png"), forState: UIControlState.Highlighted)
right_menu_button.addTarget(self, action: "menuButtonPressed", forControlEvents: .TouchUpInside)
right_menu_button.frame = CGRectMake(0, 0, menuImage!.size.width, menuImage!.size.height)
right_menu_button.autoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin


var rightButton:UIBarButtonItem = UIBarButtonItem(customView: right_menu_button)
self.navigationItem.rightBarButtonItem = rightButton

最佳答案

尝试删除这段代码:

right_menu_button.autoresizingMask = UIViewAutoresizing.FlexibleleftMargin | UIViewAutoresizing.FlexibleTopMargin

或将其更改为:

right_menu_button.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

关于ios - 导航栏中的 UINavigationItem 位置在方向上没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28337386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com