segueを使い、
遷移先で変数をインクリメントし
変数の数ごとに画像を表示させています。
表示させ終わったら元のsegueしていたところへ戻したいのですが、
前ページへ接続したButtonを表示することができず戻すことができません。
Buttonを表示する方法または
Buttonを使わず戻す方法がありましたら教えていただきたいです。
よろしくお願いいたします。
import AVFoundation import UIKit class ViewController2: UIViewController { var _imageView: UIImageView! //イメージビュー var _animeIdx = 0 //アニメーションインデックス override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } //タッチ終了時に呼ばれる override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { _animeIdx++ //イメージビューの生成 _imageView = makeImageView(self.view.frame, idx: _animeIdx) self.view.addSubview(_imageView) //ビューの生成 let nextView = makeImageView(self.view.frame, idx: _animeIdx) //UIViewアニメーションの設定開始 UIView.beginAnimations("transition", context: nil) UIView.setAnimationDuration(1.0) //トランジションアニメーションの設定(1) var transition = UIViewAnimationTransition.FlipFromLeft if _animeIdx == 1 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 2 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 3 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 4 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 5 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 6 { transition = UIViewAnimationTransition.CurlUp} if _animeIdx == 7 { transition = UIViewAnimationTransition.CurlUp} UIView.setAnimationTransition(transition, forView: self.view, cache: true) //ビューの変更(2) _imageView.removeFromSuperview() _imageView = nextView self.view.addSubview(_imageView) //UIViewアニメーションの実行 UIView.commitAnimations() //アニメーションINDEXの遷移 if _animeIdx > 7 { _animeIdx = 0 } } //イメージビューの生成 func makeImageView(rect: CGRect, idx: Int) -> UIImageView { let imageView = UIImageView() imageView.image = UIImage(named: "sample\(idx)_1.png") imageView.frame = rect imageView.contentMode = UIViewContentMode.ScaleAspectFit imageView.backgroundColor = UIColor.whiteColor() imageView.autoresizingMask = [ UIViewAutoresizing.FlexibleRightMargin, UIViewAutoresizing.FlexibleTopMargin, UIViewAutoresizing.FlexibleLeftMargin, UIViewAutoresizing.FlexibleBottomMargin, UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight] return imageView } }
回答1件
あなたの回答
tips
プレビュー