我正在做一个巨大的秘密项目,它是iOS GUI的复制品,我想制作一个动画,当我们在iOS的主屏幕上打开应用程序时。
我正在用Swift语言制作应用程序。 如果您按一个按钮,例如消息图标,消息ViewController将显示iOS动画(缩放和缩小图标)
答案 0 :(得分:1)
以下是放大和缩小动画的完整示例代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var sampleImage: UIImageView!
var isFullScreen = Bool()
var prevFrame = CGRect()
override func viewDidLoad() {
super.viewDidLoad()
isFullScreen = false
// add tap gesture into your image
var tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("imageTapped:"))
sampleImage.addGestureRecognizer(tapGestureRecognizer)
}
func imageTapped(img: AnyObject){
//Code for zoom in and zoom out animation
if !isFullScreen {
UIView.animateWithDuration (0.5, delay: 0.0, options: nil ,animations: {
self.prevFrame = self.sampleImage.frame
self.sampleImage.frame = UIScreen.mainScreen().bounds
}, completion: { _ in
self.isFullScreen = true
})
} else {
UIView.animateWithDuration (0.5, delay: 0.0, options: nil ,animations: {
self.sampleImage.frame = self.prevFrame
}, completion: { _ in
self.isFullScreen = false
})
}
}
}