如何从滚动视图中删除子视图
How to remove SubView from 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)
}
双击操作移除模糊效果
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()
}
你可以使用它:
UIView.perform(.delete, on: CardScroll, options: [], animations: {
}, completion: nil)
在下方添加以下内容blureffectView.frame
blureffectView.tag = i ; // Set tag for every view you are adding on scrollview
添加如下操作
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()
}
}
}
我已经解决了这个问题
for subview in CardScroll.subviews { if subview is UIVisualEffectView && subview.tag == pageNumber { subview.removeFromSuperview() blureffectView.removeFromSuperview() } }
如何删除选定的滚动视图模糊效果
创建滚动视图
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)
}
双击操作移除模糊效果
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()
}
你可以使用它:
UIView.perform(.delete, on: CardScroll, options: [], animations: {
}, completion: nil)
在下方添加以下内容blureffectView.frame
blureffectView.tag = i ; // Set tag for every view you are adding on scrollview
添加如下操作
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()
}
}
}
我已经解决了这个问题
for subview in CardScroll.subviews { if subview is UIVisualEffectView && subview.tag == pageNumber { subview.removeFromSuperview() blureffectView.removeFromSuperview() } }