如何从Scrollview中删除SubView

时间:2017-05-02 10:44:15

标签: ios swift scrollview

如何删除所选的scrollview blureffect

创建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)

    }

doubleTap动作删除blureffect

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()
}

3 个答案:

答案 0 :(得分:1)

在blureffectView.frame"

下面添加以下内容
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="video-gallery" class="video-list">
  <li class="play-button" data-poster="../assets/videos/posters/video-poster-1.png" data-sub-html="video caption1" data-html="#video1">
    <img src="../assets/videos/posters/video-poster-11.png" />
    <div class="gallery-poster-play-button">
      <img src="../assets/data/node_modules/lightgallery/dist/img/video-play.png" alt="">
    </div>
  </li>
  <li class="play-button" data-poster="../assets/videos/posters/video-poster-2.png" data-sub-html="video caption2" data-html="#video2">
    <img src="../assets/videos/posters/video-poster-22.png" />
    <div class="gallery-poster-play-button">
      <img src="../assets/data/node_modules/lightgallery/dist/img/video-play.png" alt="">
    </div>
  </li>
</ul>

按以下方式添加操作

 blureffectView.tag = i ; // Set tag for every view you are adding on scrollview

答案 1 :(得分:0)

你可以使用它:

UIView.perform(.delete, on: CardScroll, options: [], animations: { 

         }, completion: nil)

答案 2 :(得分:0)

我解决了这个问题

for subview in CardScroll.subviews { if subview is UIVisualEffectView && subview.tag == pageNumber { subview.removeFromSuperview() blureffectView.removeFromSuperview() } }