I suddenly remember the last time I interviewed an interviewer asking questions: How to create a diamond and have it correspond to the Click event. The effect of opening and closing.
At that time the first reaction using button to fill the picture of the diamond to achieve, but the examiner said that the area of the click is not sensitive, after all, the button is rectangular. At that time was indeed questioned by the examiner, and later thought up, found so!
You may have seen this function: SetTransform: Yes. The principle we are implementing is to rotate the square button 45 degrees. into a rectangle. Combining precise coordinate calculation, the UIView animation is adopted to realize the opening and closing effect.
is not very easy it ~
Suppose you don't want to use a button with ImageView to increase gesture recognition to correspond to click events. Post code:
[_myimage settransform:cgaffinetransformmakerotation (M_pi_4)]; [_myimage2 settransform:cgaffinetransformmakerotation (M_pi_4)]; [_myimage3 settransform:cgaffinetransformmakerotation (M_pi_4)]; [_myimage4 settransform:cgaffinetransformmakerotation (M_pi_4)];
The above is the four image that will be declared rotated 45 degrees. Next is the animation:
[UIView animatewithduration:0.7 animations:^{ //move picture _myimage.center = Cgpointmake (_myimage.center.x, _ Myimage.center.y-length); _myimage2.center = Cgpointmake (_myimage2.center.x-length, _myimage2.center.y); _myimage3.center = Cgpointmake (_myimage3.center.x+length, _myimage3.center.y); _myimage4.center = Cgpointmake (_myimage4.center.x, _myimage4.center.y+length); length =-length; }]
It is easier to move the center of each picture. Here I have achieved four different animation effects, see the code for details.
Finally effects such as the following:
IOS----Quad Block animation button implementation