scrollviewを使おうとして下記のようなコードを書いたのですが、contentOffsetのところでどうしてもエラーがでてしまいます。
エラー名はvalue of type 'UIImageView' has no member 'contentOffset'です。
何やらImageViewに問題がありそうですが、よくわかりません・・・
教えていただけたら幸いです。
swift
1import UIKit 2 3class ViewController2: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate { 4 5 @IBOutlet weak var imageview: UIImageView! 6 @IBOutlet weak var textView: UITextView! 7 @IBOutlet weak var scrollview: UIImageView! 8 9 10 var txtActiveView = UITextView() 11 12 13 14 override func viewDidLoad() { 15 super.viewDidLoad() 16 // Do any additional setup after loading the view, typically from a nib. 17 18 } 19 20 override func didReceiveMemoryWarning() { 21 super.didReceiveMemoryWarning() 22 // Dispose of any resources that can be recreated. 23 //aaaaaa 24 } 25 26 func textFieldShouldBeginEditing(textView: UITextView!) -> Bool { 27 txtActiveView = textView 28 return true 29 } 30 31 func textFieldShouldReturn(textView: UITextView!) -> Bool { 32 view.endEditing(true) 33 return true 34 } 35 36 37 38 func handleKeyboardWillShowNotification(notification: NSNotification) { 39 40 let userInfo = notification.userInfo! 41 let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 42 let myBoundSize: CGSize = UIScreen.mainScreen().bounds.size 43 44 let txtLimit = txtActiveView.frame.origin.y + txtActiveView.frame.height + 8.0 45 let kbdLimit = myBoundSize.height - keyboardScreenEndFrame.size.height 46 47 48 49 if txtLimit >= kbdLimit { 50 scrollview.contentOffset.y = txtLimit - kbdLimit 51 } 52 } 53 54 func handleKeyboardWillHideNotification(notification: NSNotification) { 55 scrollview.contentOffset.y = 0 56 } 57 58 59 override func viewWillAppear(animated: Bool) { 60 super.viewWillAppear(animated) 61 62 let notificationCenter = NSNotificationCenter.defaultCenter() 63 notificationCenter.addObserver(self, selector: #selector(ViewController2.handleKeyboardWillShowNotification(_:)), name: UIKeyboardWillShowNotification, object: nil) 64 notificationCenter.addObserver(self, selector: #selector(ViewController2.handleKeyboardWillHideNotification(_:)), name: UIKeyboardWillHideNotification, object: nil) 65 } 66 67 override func viewDidDisappear(animated: Bool) { 68 super.viewDidDisappear(animated) 69 70 let notificationCenter = NSNotificationCenter.defaultCenter() 71 notificationCenter.removeObserver(self, name: UIKeyboardWillShowNotification, object: nil) 72 notificationCenter.removeObserver(self, name: UIKeyboardWillHideNotification, object: nil) 73 } 74 75 76 77 78 79} 80
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/12 04:04