2016-07-29 2 views
1

스토리 보드에 나는 ViewController이라는 집이 있습니다.CGPoint가 2 초 동안 뷰 내에있는 경우에만 기능 시작

홈에는 서브 뷰로 빨간색 UIView이 있고 홈 센터에 있습니다.

빨간보기에는 LongPressGestureRecognizer이 있습니다. 활성화되면 사용자는 화면에서 빨간색보기를 이동할 수 있습니다.

사용자가 빨간색보기를 화면 왼쪽으로 충분히 가까이 이동하면 UIViewSidebar이 튀어 나옵니다.

사이드 바 내에서 n 고유 한 색 subviews입니다.

사용자가 컬러 파단의 프레임 내에서 빨간색보기를 이동

는 색상 mix 사이드 바의 색상이 빨간색으로보기 변경 색상을 만진 것이다. 그것은 혼합으로 바뀝니다.

`

func handleAuditioneeLongPress(sender: UILongPressGestureRecognizer) { 
     switch sender.state { 
     case .Began: 
      hideSideBar() 
     case .Changed: 
      let touchPoint = sender.locationInView(self.view) 
      thumbnailTrackTouchPoint(touchPoint) 
     case .Ended: 
      let dropPoint = sender.locationInView(self.view) 
      thumbnailWasDropped(dropPoint) 
     default: 
      break 
     } 
    } 
func thumbnailTrackTouchPoint(touchPoint: CGPoint){ 
     UIView.setAnimationsEnabled(true) 
     UIView.animateWithDuration(0.03, delay: 0.0, options: [.BeginFromCurrentState, .CurveEaseOut], animations: { 
       self.red.center.x = touchPoint.x 
      self.red.center.y = touchPoint.y - 50 
      }, completion: nil) 
    if touchPoint.x < 30{ 
     showSidebar() 
     isSidebarOut = true 
     } 
    if isSidebarOut { 
      if touchPoint.x > 135 { 
       hideSideBar() 
       isSidebarOut = false 
      } 

      let location = self.view.convertPoint(touchPoint, toView: sidebar) 
      let subview = sidebar.hitTest(location, withEvent: nil) 
      if(subview != nil) { 
      if let coloredIconController = self.sidebarController.viewToColoredIconController[subview!] 


/* 
if coloredIconController.view.frame.contains(location) for more than 2 seconds mix the colors 
*/ 

` 는 사용자의 기동 사이드 바 있지만,이 실수로 혼합을 원하지 않는다.

그래서 확인 조건이 필요합니다. 터치 포인트가 2 초 동안 색상이 지정된보기에 포함 된 경우에만 빨간색을 혼합해야합니다. 점보기

myTimer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: "mixing method", userInfo: userInfo, repeats: false) 

들어갈 때 당신에게 단지

if myTimer != nil { 
    myTimer.invalidate() 
} 
+0

을 얻을 cgpoint 때 – Larme

+0

혼합하는 방법으로 지역 화재 예정된 타이머를 입력 할 때 실행되는 메서드에서 해당 영역에서 벗어날 때 실행되는 메서드에서 타이머를 무효화하는 메서드가 이미 없으면 –

답변

1

는 예약 타이머를 시작`당신이 단지 변경에 발생하는 저장 날짜 매개 변수를 추가 할 수 thumbnailTrackTouchPoint` 및 그것이 한도를 벗어나면 그것은 삭제되거나 현명한 설정이됩니다. 그런 다음 종료되면 2 초 이상 차이인지 확인할 수 있습니다.