How to detect when UIImageView flip vertically

别来无恙 提交于 2019-12-11 04:31:53

问题


I check from UIImageView's scaleY but it doesn't work (see the code below).

CGAffineTransform t = [myImageView transform]; // Keep matrix value of UIImageView
float scaleY1 = sqrt(t.b * t.b + t.d * t.d);   // 1.0000
CGAffineTransform t2 = CGAffineTransformScale(t, 1, -1.0); // flip UIImageView vertically
float scaleY2 = sqrt(t2.b * t2.b + t2.d * t2.d); // 1.0000
[myImageView setTransform:t2];
NSLog(@"1: %f, 2: %f", scaleY1, scaleY2); // 1: 1.0000, 2: 1.0000

From above, you can see that before and after we flip the UIImageView, we got the same "scaleY value".

What is the value that we should check? (in order to detect when UIImageView flip vertically)


回答1:


What about checking the transform property of the imageview? You will see there if the view has been transformed. This is what I see if I print the value of myImageView in console after aplying the transformation:

(lldb) po myImageView

UIImageView: 0x8f59f30; frame = (0 0; 0 0); transform = [1, 0, -0, -1, 0, 0]; userInteractionEnabled = NO;




回答2:


You can try this

[UIView transitionWithView: flipTile
                  duration: 0.5
                   options: UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    flipTile.image = newTileImage;
                }
                completion:^(BOOL finished) {
                    /*
                        code after completion
                    */
                }
 ];



回答3:


The answer of jay gajjar is fine.

But if you dont want to animate then use

[UIView transitionWithView: flipTile
                  duration: 0.0
                   options: UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    flipTile.image = newTileImage;
                }
                completion:^(BOOL finished) {
                    /*
                        code after completion
                    */
                }
 ];


来源:https://stackoverflow.com/questions/19855422/how-to-detect-when-uiimageview-flip-vertically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!