私は2つの画像を切り替えたいので、魚とfishaと呼ぶことができます。 UIImageViewはplayerと呼ばれるため、コードは次のようになります。スイフト[UIImage]がSwiftに設定されました
@IBOutlet weak var player: UIImageView!
var images: [UIImage] = []
images.append(UIImage(named: "fish")!)
images.append(UIImage(named: "fisha")!)
player.frame = CGRectMake((screenWidth-px)/2, (screenHeight-py)/2, px, py)
player.animationImages = images
player.animationDuration = 0.7
player.startAnimating()
これはすべて問題なく動作します。しかし、今、私はplayer2というUIImageViewを作成したいと言っています。これは、プレーヤーのミラーバージョンでなければなりません。私はそれが正常に動作することを期待しplayer2を作るために、コードのこの変更に伴い
func flipH(im:UIImage)->UIImage {
var newOrient:UIImageOrientation
switch im.imageOrientation {
case .Up:
newOrient = .UpMirrored
case .UpMirrored:
newOrient = .Up
case .Down:
newOrient = .DownMirrored
case .DownMirrored:
newOrient = .Down
case .Left:
newOrient = .RightMirrored
case .LeftMirrored:
newOrient = .Right
case .Right:
newOrient = .LeftMirrored
case .RightMirrored:
newOrient = .Left
}
return UIImage(CGImage: im.CGImage!, scale: im.scale, orientation: newOrient)
}
:
この機能を使用します。
@IBOutlet weak var player2: UIImageView!
var images: [UIImage] = []
images.append(flipH(UIImage(named: "fish")!))
images.append(flipH(UIImage(named: "fisha")!))
player2.frame = CGRectMake((screenWidth-px)/2, (screenHeight-py)/2, px, py)
player2.animationImages = images
player2.animationDuration = 0.7
player2.startAnimating()
ただし、それはありません。 Player2はプレーヤーと同じです。誰にも何か考えがありますか?
おかげで、 トム
ああ、私が望むようにプログラムでUIImagesを反転する方法はありませんか? –
ありがとうございます。あなたがやっていることだけではありません。 – matt