2015-11-07 38 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這樣做。