Swift 为什么动画和水平运动效果之间会发生这种奇怪的行为?
我测试了一些代码,最后得到了以下代码:Swift 为什么动画和水平运动效果之间会发生这种奇怪的行为?,swift,uiviewanimation,Swift,Uiviewanimation,我测试了一些代码,最后得到了以下代码: import UIKit class ViewController: UIViewController { @IBOutlet var backgroundImageView: UIImageView! override func viewDidAppear(animated: Bool) { super.viewDidAppear(true) hideAndShow() } func hideAndShow(){
import UIKit
class ViewController: UIViewController {
@IBOutlet var backgroundImageView: UIImageView!
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
hideAndShow()
}
func hideAndShow(){
self.backgroundImageView.alpha = 0
UIView.animateWithDuration(1.0, delay: 0, options: .Repeat | .AllowUserInteraction | .Autoreverse | UIViewAnimationOptions.CurveEaseOut, animations: { [weak self] in
self?.backgroundImageView.alpha = 1
}, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
self.backgroundImageView.contentMode = UIViewContentMode.Center;
self.backgroundImageView.backgroundColor = UIColor(patternImage: UIImage(named: "640x1136launch")!)
self.addParallaxEffectToView(self.backgroundImageView)
self.backgroundImageView.frame = CGRectInset(self.backgroundImageView.frame, -50, -50);
}
func addParallaxEffectToView(view: UIView ) {
// Set vertical effect
var verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: UIInterpolatingMotionEffectType.TiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = -50
verticalMotionEffect.maximumRelativeValue = 50
// Set horizontal effect
var horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: UIInterpolatingMotionEffectType.TiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = -50
horizontalMotionEffect.maximumRelativeValue = -50
// Create group to combine both
var group = UIMotionEffectGroup.new()
group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
// Add both effects to your view
view.addMotionEffect(group);
}
}
这段代码的作用是在我的UIViewController
上的UIImage
上产生闪烁效果
此图像还具有UIMotionEffect(在本例中为tilt)效果,在垂直倾斜设备时效果非常理想,但由于某些原因,在水平倾斜设备时效果不理想
尽管如此,关键是当我调用我的hideandShow()
函数时,我的视图开始闪烁,但同时,…开始水平移动
为什么会这样?我没有主意了