IOS----Quad Block animation button implementation

Source: Internet
Author: User

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

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.