2016-01-05 69 views
0
super.viewDidLoad() 

    let tapGesture = UITapGestureRecognizer(target: self, action: Selector("hideKeyboard")) 
    tapGesture.cancelsTouchesInView = true 

    scrlView.addGestureRecognizer(tapGesture) 

    //self.navigationController!.navigationBarHidden = true 

    scrlView.contentSize = CGSizeMake(UIScreen .mainScreen().bounds.size.width, (regButton.frame.size.height + regButton.frame.origin.y)+20) 

    // Do any additional setup after loading the view. 
} 

func hideKeyboard() { 
    scrlView.endEditing(true) 
    scrlView .setContentOffset(CGPointMake(0, 0), animated: true) 
} 


@IBAction func tapped(sender: AnyObject) { 

    scrlView.endEditing(true) 
    scrlView .setContentOffset(CGPointMake(0, 0), animated: true) 
} 

我的hideKeyboard功能正常。但是现在我想要敲击键盘上方文本框的位置。如何使用水龙头手势放置文本框位置

+0

究竟你需要什么意思当文本字段开始编辑,然后它应该向上滚动? –

+0

准确.. @Shubhambairagi –

+0

然后你需要做的是设置委托'textFieldShouldReturn'。这里设置滚动视图的偏移量。并在tapGausture上重新设置。请在下面查看我的答案 –

回答

1

试试这个:

func textFieldShouldBeginEditing(textField: UITextField) -> Bool{ 
    scrl.setContentOffset(CGPointMake(0.0, textField.center.y-120), animated: true) 
} 

和你func hideKeyboard()应保持相同 希望它会对你有帮助

+0

你可以设置'ContentOffset'根据你的要求 –

+0

不能。 @Shubhambairagi –

+0

FUNC textFieldShouldReturn(文本框:的UITextField) - >布尔{ textField.resignFirstResponder() scrlView .setContentOffset(CGPointMake(0,0),动画:真) 返回真 } 我已经使用这个方法。 –

相关问题