【发布时间】:2015-05-21 00:41:08
【问题描述】:
这已经困扰我几个小时了,我似乎找不到解决方案:(。
我有一个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:) 尝试了相反的方法
【问题讨论】:
-
现在我上传了图像,我注意到视图的位置不同。也许 vwCard 没有从 superview 中删除?
-
你为什么不在故事板上制作那张卡片,拿一个 IBOutlet 并最初隐藏它,然后你可以随时取消隐藏它!
标签: ios swift ios7 ios8 keywindow