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

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

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

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

Q&A

解決済

1回答

1768閲覧

アニメーションの座標がわかりません②

aaaaaachannel

総合スコア37

Swift

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

0グッド

0クリップ

投稿2018/01/30 06:20

流れる画面を作りたいです。
そこでlargeImageView という大きなImageviewを作り、そこに画像をつなげていき、そのlargeImageViewを動かそうと考えました。
全部で9枚(number)の画像が繋がり、流れていくと思ったのですが、シュミレーターを動かすと、
画像3.5枚分ほどの白い画面が流れた後、残り5.5枚ほどの画像が繋がって画面を流れます。
どこの座標の設定がおかしいのでしょうか。
どうしてもわかりません、よろしくお願いします。

swift

1 var imageViewArray:Array<UIImageView> = [] 2 let img = UIImage(named: "background") 3 let imageView = UIImageView(image:img) 4 imageHeight = imageView.bounds.height*CGFloat(number) 5 largeImageView.frame = CGRect(x: 0, y: 0,width:self.view.frame.width,height:imageHeight) 6 7 8 9 for i in 0..<number{ 10 let imageView = UIImageView(image:img) 11 imageView.frame = CGRect(x: 0, y: CGFloat(i) * -imageView.bounds.height,width:self.view.frame.width,height:imageView.bounds.height) 12// self.view.sendSubview(toBack: imageView) 13 largeImageView.addSubview(imageView) 14 imageViewArray.append(imageView) 15 } 16 17 view.addSubview(largeImageView) 18 19 20 // アニメーション処理 21 22 let animation = CABasicAnimation(keyPath: "position.y") 23 animation.duration = 20.0 24 animation.fromValue = -view.bounds.size.height/2 25 animation.toValue = imageHeight-view.bounds.size.height/2 26 largeImageView.layer.add(animation, forKey: nil)

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

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

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

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

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

guest

回答1

0

ベストアンサー

swift

1imageView.frame = CGRect(x: 0, y: CGFloat(i) * -imageView.bounds.height,width:self.view.frame.width,height:imageView.bounds.height)

マイナス不要では?

投稿2018/01/30 06:35

fuzzball

総合スコア16731

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

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

aaaaaachannel

2018/01/31 01:53

回答ありがとうございます。 そうしても5枚が流れた後、白い画面の時間があって、最後にまた画像が現れるのですがなぜでしょうか?
fuzzball

2018/01/31 02:00

全てのImageViewのY座標を教えてもらえますか?
aaaaaachannel

2018/01/31 02:06

(0.0, -1200.0, 414.0, 1200.0) (0.0, -2400.0, 414.0, 1200.0) (0.0, -3600.0, 414.0, 1200.0) (0.0, -4800.0, 414.0, 1200.0) (0.0, -6000.0, 414.0, 1200.0) (0.0, -7200.0, 414.0, 1200.0) (0.0, -8400.0, 414.0, 1200.0) (0.0, -9600.0, 414.0, 1200.0) imageviewの画像は一つでfor文で回すと-の時は上の座標で+だと単純に-がプラスになります。 largeimageviewの座標は (0.0, 0.0, 414.0, 10800.0) です。
aaaaaachannel

2018/01/31 03:01

let number =9 let largeImageView = UIImageView() var imageHeight:CGFloat! func setBackGround(){ //背景 var imageViewArray:Array<UIImageView> = [] let img = UIImage(named: "background") let imageView = UIImageView(image:img) imageHeight = imageView.bounds.height*CGFloat(number) largeImageView.frame = CGRect(x: 0, y:-imageHeight,width:self.view.frame.width,height:imageHeight) for i in 0..<number{ let imageView = UIImageView(image:img) imageView.frame = CGRect(x: 0, y: CGFloat(i) * -imageView.bounds.height,width:self.view.frame.width,height:imageView.bounds.height) // self.view.sendSubview(toBack: imageView) largeImageView.addSubview(imageView) imageViewArray.append(imageView) print(imageView.frame) } view.addSubview(largeImageView) // アニメーション処理 UIView.animate(withDuration: 2.0, delay: 0, options: [.curveEaseIn, .curveEaseOut], animations: { }) { _ in self.largeImageView.frame = CGRect(x: 0, y: 0,width:self.view.frame.width,height:self.imageHeight) } 上のコードだと画像が動きません。largeImageViewでやろうとすることが間違いでしょうか?
aaaaaachannel

2018/01/31 03:21

流れました!!animatedurationの方がやりやすかったです!ありがとうございました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問