IOS ---- four-square Animation button implementation, ios ---- Square
Suddenly think of a question asked by the examiner in the last interview: How to Create a diamond, and let it click the event accordingly, the effect can be opened and closed. At that time, the first reaction was to use the button to fill the diamond image, but the examiner said that the clicked area was not sensitive enough. After all, the button was rectangular. At that time, I was really asked by the examiner. Later I thought of it and found it was like this!
You may have seen this function: setTransform: Yes. Our principle is to rotate the square button 45 degrees to a rectangle. With precise coordinate calculation, you can use UIView animation to achieve the effect of opening and closing. Isn't it easy ~
If you do not want to use the imageView button, you can add Gesture Recognition to click the event accordingly. 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 shows that the declared four images are rotated 45 degrees. Next is the animation:
[UIView animateWithDuration: 0.7 animations: ^ {// move image _ 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 convenient to move the center of each image. Here I have implemented four different animation effects. For details, see the code.
The final result is as follows:
If the Android mobile phone deletes the blue icon in the middle of the screen (four blocks in it), how can it enter the menu?
Long press the screen and select this menu icon in the gadgets to add one.
That is not where it is necessary. You can place it anywhere on any screen, just like other software.
How to create four blocks