如何删除选定的 ScrollView 模糊效果
创建 ScrollView
for i in 0 ... totalPage {
let cardView = Bundle.main.loadNibNamed("cardView", owner: self, options: nil)?[0] as! UIView
cardView.frame = CGRect(x: CGFloat(i) * CardScroll.frame.size.width, y: CardScroll.frame.origin.y, width: CardScroll.frame.size.width, height: CardScroll.frame.size.height)
let blureffect = UIBlurEffect(style: UIBlurEffectStyle.light)
blureffectView = UIVisualEffectView(effect: blureffect)
blureffectView.frame = CGRect(x: CGFloat(i) * CardScroll.frame.size.width, y: CardScroll.frame.origin.y, width: CardScroll.frame.size.width, height: CardScroll.frame.size.height)
CardScroll.addSubview(cardView)
CardScroll.addSubview(blureffectView)
}
双击 Action 移除模糊效果
func doubleTapped() {
let pageNumber = CardPage.currentPage
blureffectView.frame = CGRect(x: CGFloat(pageNumber) * CardScroll.frame.size.width, y: CardScroll.frame.origin.y, width: CardScroll.frame.size.width, height: CardScroll.frame.size.height)
blureffectView.removeFromSuperview()
}
最佳答案
在 blureffectView.frame 下方添加以下内容
blureffectView.tag = i ; // Set tag for every view you are adding on scrollview
添加 Action 如下
func doubleTapped(sender:UIButton!){ // Pass sender as UIButton so you can get tag here
for subview in scrollView.subviews{ // Loop thorough ScrollView view hierarchy
if subview is UIVisualEffectView && subview.tag == sender.tag { // Check if view is type of VisualEffect and tag is equal to the view clicked
subview.removeFromSuperview()
}
}
}
关于ios - 如何从 ScrollView 中删除 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43735944/