質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1667閲覧

swift scrollviewについて

hirotoshin

総合スコア24

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2016/10/12 02:55

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Swift

1@IBOutlet weak var scrollview: UIImageView!

scrollViewUIImageView型で宣言されていますよ。

Swift

1@IBOutlet weak var scrollview: UIScrollView!

ではありませんか?

投稿2016/10/12 03:03

Y_M

総合スコア265

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hirotoshin

2016/10/12 04:04

すみません。その通りでした。 ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問