有沒有辦法獲得外部屏幕邊框和酒吧按鈕項目之間的距離。我正在考慮類似如何獲得狀態欄高度?屏幕邊框和酒吧按鈕項目之間的距離
(我問這個,因爲這取決於設備是不同的)
let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, view.frame.size.width, 64))
let navigationBar.backgroundColor = UIColor.redColor()
let barButtonItem = UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: nil)
navigationItem.leftBarButtonItem = barButtonItem
navigationBar.items = [navigationItem]
let buttonItemView = barButtonItem.valueForKey("view") as! UIView
let frame = buttonItemView.superview!.convertRect(buttonItemView.frame, toView: UIApplication.sharedApplication().keyWindow?.rootViewController?.view)
let xCoordinateMin = CGRectGetMinX(frame)
let yCoordinateMax = CGRectGetMaxY(frame)
let yCoordinateMin = CGRectGetMinY(frame)
let label = UILabel(frame: CGRectMake(CGFloat(xCoordinateMin), CGFloat(yCoordinateMin), 100, yCoordinateMax - yCoordinateMin))
label.backgroundColor = UIColor.greenColor()
但它仍然給我0作爲XMIN,雖然它似乎與工作y座標..
好的,謝謝,我已經走這..但我想知道的外屏幕邊框和酒吧按鈕項目之間的距離。 – manu