这已经困扰了我几个小时了,我似乎找不到解决方案:(。
我有一个UITableView
,当我单击一行时,我想在“卡片”中显示该行的详细信息。我在 keywindow 中添加卡片是因为我希望它在 上方,并且在卡片的背景中UINavigationBar
有一个透明的视图
这就是我的代码的样子
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.vwCard.removeFromSuperview()
let keyWindow = UIApplication.sharedApplication().keyWindow
let screen = UIScreen.mainScreen().bounds
vwTransparentView = UIView(frame: screen)
vwTransparentView.backgroundColor = UIColor.blackColor()
vwTransparentView.hidden = true
vwTransparentView.userInteractionEnabled = false
keyWindow?.addSubview(self.vwCard)
keyWindow?.insertSubview(self.vwTransparentView, belowSubview: self.vwCard)
vwCard.center = CGPointMake((screen.width/2), (screen.height/2))
vwCard.hidden = true
vwCard.layer.borderColor = UIColor.whiteColor().CGColor
}
当我单击UITableView
行时,会发生这种情况
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
vwCard.hidden = false
vwCard.alpha = 0
vwTransparentView.alpha = 0
vwTransparentView.hidden = false
vwCard.transform = CGAffineTransformMakeScale(1.2, 1.2)
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.vwCard.alpha = 1
self.vwCard.transform = CGAffineTransformIdentity
self.vwTransparentView.alpha = 0.4
})
}
这是 iOS 7 (7.1) 中屏幕的样子
这就是它在 iOS 8 (8.3) 中的样子
我希望它在 iOS 8 中的外观与在 iOS 7 中的外观相同。我不知道为什么keyWindow?.insertSubview(self.vwTransparentView, belowSubview: self.vwCard)
不起作用。我也尝试过相反的方法insertSubview( ,aboweView:)