2014-09-01 2 views
0

내보기 중 하나에 두 개의 텍스트 필드가 있고 어떤 텍스트 필드가 도청되었는지에 따라 다른 위치로보기를 이동하는 방법을 파악하려고합니다.입력 한 텍스트 필드를 기반으로 UIView 이동

뷰 컨트롤러의 상단과 키보드 사이에 두 텍스트 필드가 들어갈 수있는 충분한 공간이 있으므로보기를 이동하는 기능은 4 인치 장치에서 절대적으로 잘 작동합니다. 그러나 3.5 인치 장치에는 한 번에 하나의 텍스트 필드 만 표시 할 수있는 충분한 공간이 있습니다.

viewWillAppear : 여기

내가 현재 가지고있는 코드입니다

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil) 

keyboardWillShow/keyboardWillHide : 나는 도청 및 이동 된 텍스트 필드 알아낼 수있는 방법

override func viewWillDisappear(animated: Bool) { 
    NSNotificationCenter.defaultCenter().removeObserver(self) 
} 

func keyboardWillShow(notification: NSNotification) { 
    var screenSize = UIScreen.mainScreen().bounds.size.height 

    if screenSize == 480 { 
     // 
    } else { 
     if keyboardActive == false { 
      if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
       //let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0) 
       var frame = self.budgetEntryView.frame 
       frame.origin.y = frame.origin.y - 87 //keyboardSize.height + 167 
       self.budgetEntryView.frame = frame 
       keyboardActive = true 
      } 
     } 
    } 
} 

그걸 바탕으로보기?

답변

1

각 textView에 대해 isFirstResponder 메소드를 호출하여 어느 것이 탭되었는지 찾아냅니다.

+0

완벽하게 작동합니다. 고마워. – user3746428

관련 문제