2017-03-14 8 views
0

단추를 클릭했을 때 background_image가 흐림 효과로 바뀝니다.단추로 사용하려면 BlurEffect를 먼저 제거하십시오.

@IBAction func button_MainClicked2(_ sender: UIButton) { 
     if button_MainCenter == button_viajes.center{ 
      UIView.animate(withDuration: 0.6, animations: 

     { 

      let blur = UIBlurEffect(style: UIBlurEffectStyle.light) 
      let blurView = UIVisualEffectView(effect: blur) 
      blurView.frame = self.image_Background.bounds 
      self.image_Background.addSubview(blurView)  

     }) 
     } else { 
      UIView.animate(withDuration: 0.6, animations: { 
       // I want to remove blur effect as soon as i press the button again. 
      }) 
     } 
    } 

버튼을 다시 클릭하면 바로 효과를 제거 할 수 있습니까?

답변

0

당신은 애니메이션 블록에서 다음 하위 뷰로 추가하기 전에 tagblurView.tag = 1000 같은 전망을 흐리게 추가 할 수 있습니다

for view in button_MainCenter.subviews { 
    if view.tag == 1000 { 
     view.removeFromSuperview() 
    } 
} 

편집 : 그것은 비록 애니메이션 될 경우 확실하지 않다. 그렇지 않은 경우이 뷰의 alpha에 1에서 0까지 애니메이션을 적용한 다음 제거 할 수 있습니다.

편집 : 당신이 파단을 반복하지 않으려면

let blur = UIBlurEffect(style: UIBlurEffectStyle.light) 
let blurView = UIVisualEffectView(effect: blur) 
blurView.tag = 1000 
blurView.frame = self.image_Background.bounds 
self.image_Background.addSubview(blurView) 
+1

당신은 또한 단지'말할 수있는 경우 blurView = imageBackground.viewWithTag (태그 : 1000)을 보자 {...}' – creeperspeak

+0

덕분에 남자 ,하지만 여전히 작동하지 않습니다. 이 태그를 어디에 추가해야합니까? 이 코드를 다른 코드보다 먼저 작성해야합니까? 고마워요 –

+0

@ EloyuF.Bent 코드를 추가했습니다. – JuicyFruit