2015-11-07 37 views
1

基本的新手问题。翻转图像以显示背部iOS

我正在寻找将几个图像放入一个集合视图。我如何将图像翻转以使用swift在Xcode中显示图像的背面?感谢大家的帮助。

+0

从git hub检查出这个项目,这可以帮助你。 http://advanceioscode.blogspot.com/2015/11/colour-memory-44-grid-project.html – GameLoading

+1

谢谢您的项目链接。这正是我所期待的。再次感谢帮助。我期待尽快为社区做出贡献。 –

+0

我不确定我是否理解翻转图像以揭示它的背面。你在谈论水平翻转过渡吗? –

回答

3

我不确定你到底想要达到什么目的,但是我正在使用此功能来水平旋转图像并在转换过程中更改图像。希望能帮助到你。

private func flipImageView(imageView: UIImageView, toImage: UIImage, duration: NSTimeInterval, delay: NSTimeInterval = 0) 
{ 
    let t = duration/2 

    UIView.animateWithDuration(t, delay: delay, options: .CurveEaseIn, animations: {() -> Void in 

     // Rotate view by 90 degrees 
     let p = CATransform3DMakeRotation(CGFloat(GLKMathDegreesToRadians(90)), 0.0, 1.0, 0.0) 
     imageView.layer.transform = p 

    }, completion: { (Bool) -> Void in 

     // New image 
     imageView.image = toImage 

     // Rotate view to initial position 
     // We have to start from 270 degrees otherwise the image will be flipped (mirrored) around Y axis 
     let p = CATransform3DMakeRotation(CGFloat(GLKMathDegreesToRadians(270)), 0.0, 1.0, 0.0) 
     imageView.layer.transform = p 

     UIView.animateWithDuration(t, delay: 0, options: .CurveEaseOut, animations: {() -> Void in 

      // Back to initial position 
      let p = CATransform3DMakeRotation(CGFloat(GLKMathDegreesToRadians(0)), 0.0, 1.0, 0.0) 
      imageView.layer.transform = p 

     }, completion: { (Bool) -> Void in 
     }) 
    }) 
} 

不要忘记导入GLKit。

+0

感谢您的指导。我也会试试这个。 –

0
-(void)showButtton 
{ 
self.userInteractionEnabled = false; 
[UIView transitionWithView:self duration:0.3 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ 
//code to change the image of UIButton 
} completion:^(BOOL finished) { 
self.userInteractionEnabled = true; 
}]; 
} 

这是一个code这样做。