我想要切换两张图片,让我们称之为鱼和fisha。 UIImageView被称为播放器,因此代码如下:
@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,它应该是播放器的镜像版本。
使用此功能:
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)
}
随着对代码的修改以使player2我希望它能够正常工作。
@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与玩家完全相同。有谁知道为什么?
谢谢, 汤姆