我正在为国际象棋制作一个计时器,我希望只要其中一方不玩,就会有模糊,但出于某种原因,下面的代码将模糊效果放在错误的位置,除非应用程序是从横向模式打开的:
var blackSeconds: Int = 0
var whiteSeconds: Int = 0
var blackTimer: Timer = Timer()
var whiteTimer: Timer = Timer()
let blurEffectViewForBlack = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
let blurEffectViewForWhite = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
override func viewDidLoad() {
super.viewDidLoad()
blackLabel.text = formatTime(time: blackSeconds)
whiteLabel.text = formatTime(time: whiteSeconds)
inputOutlet.attributedPlaceholder = NSAttributedString(
string: "Enter number of seconds",
attributes: [NSAttributedStringKey.foregroundColor: UIColor.lightGray]
)
let width: CGFloat = self.view.frame.size.width
let height: CGFloat = self.view.frame.size.height
print(width, height)
blurEffectViewForBlack.frame = CGRect(x: 0, y: 0, width: width / 2, height: height)
blurEffectViewForBlack.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurEffectViewForBlack.alpha = 0.9
blurEffectViewForBlack.isHidden = true
blurEffectViewForWhite.frame = CGRect(x: width / 2, y: 0, width: width / 2, height: self.view.bounds.height)
blurEffectViewForWhite.autoresizingMask = [.flexibleWidth, .flexibleHeight]
blurEffectViewForWhite.alpha = 0.9
blurEffectViewForWhite.isHidden = true
view.addSubview(blurEffectViewForBlack)
view.addSubview(blurEffectViewForWhite)
}
我担心这与self.view.frame.size
根据方向不会改变这一事实有关。请注意,我还尝试了self.view.bounds
,它产生了相同的结果。见here。