我在这里错过了什么吗?我有一个名为的类的成员变量:@H_403_3@
var activeTextFIEld: UITextFIEld!
我是否正确使用了委托方法?@H_403_3@
(func registerForKeyboardNotifications() { let notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addobserver(self,selector: "keyboarDWillBeShown:",name: UIKeyboarDWillShowNotification,object: nil) notificationCenter.addobserver(self,selector: "keyboarDWillBeHIDden:",name: UIKeyboarDWillHIDeNotification,object: nil)}func keyboarDWillBeShown(sender: NSNotification) { let info: NSDictionary = sender.userInfo! let value: NSValue = info.valueForKey(UIKeyboardFrameBeginUserInfoKey) as NSValue let keyboardSize: CGSize = value.CGRectValue().size let contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0,0.0,keyboardSize.height,0.0) scrollVIEw.contentInset = contentInsets scrollVIEw.scrollindicatorInsets = contentInsets // If active text fIEld is hIDden by keyboard,scroll it so it's visible // Your app might not need or want this behavior. var aRect: CGRect = self.vIEw.frame aRect.size.height -= keyboardSize.height let activeTextFIEldRect: CGRect? = activeTextFIEld?.frame let activeTextFIEldOrigin: CGPoint? = activeTextFIEldRect?.origin if (!CGRectContainsPoint(aRect,activeTextFIEldOrigin!)) { scrollVIEw.scrollRectToVisible(activeTextFIEldRect!,animated:true) }}// Called when the UIKeyboarDWillHIDeNotification is sentfunc keyboarDWillBeHIDden(sender: NSNotification) { let contentInsets: UIEdgeInsets = UIEdgeInsetsZero scrollVIEw.contentInset = contentInsets scrollVIEw.scrollindicatorInsets = contentInsets}func textFIEldDIDBeginEditing(textFIEld: UITextFIEld!) { activeTextFIEld = textFIEld scrollVIEw.scrollEnabled = true}func textFIEldDIDEndEditing(textFIEld: UITextFIEld!) { activeTextFIEld = nil scrollVIEw.scrollEnabled = false}overrIDe func vIEwWillAppear(animated: Bool) { super.vIEwWillAppear(animated) self.registerForKeyboardNotifications()}overrIDe func vIEwDIDdisappear(animated: Bool) { super.vIEwWilldisappear(animated) NSNotificationCenter.defaultCenter().removeObserver(self)}解决方法 我这样做了,它对我有用.似乎比你的方式容易多了.我为我的项目使用了UITextVIEw.但它应该与UITextFIEld一样. – / 25只是为了让标题显示出来.
func textVIEwDIDBeginEditing(textVIEw: UITextVIEw) { myScrollVIEw.setContentOffset(CGPointMake(0,textVIEw.frame.origin.y-25),animated: true)}func textVIEwDIDEndEditing(textVIEw: UITextVIEw) { myScrollVIEw.setContentOffset(CGPointMake(0,-textVIEw.frame.origin.y+25),animated: true)}总结
以上是内存溢出为你收集整理的ios – Swift,移动键盘后面的内容在关闭后不会重置全部内容,希望文章能够帮你解决ios – Swift,移动键盘后面的内容在关闭后不会重置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)