IOS ---- four-square Animation button implementation, ios ---- Square

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.