1
我在導航欄中的右側導航項目上添加了自定義圖像。但是當我旋轉設備的右側按鈕項目堅持肖像位置。導航欄中的UINavigationItem位置在方向上未改變
肖像
景觀
正如你可以看到,從縱向改爲橫向時的菜單圖標貼到原來的位置。
代碼
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.FlexibleHeight –