Defines the effect of a button press to show the masking layer

Source: Internet
Author: User

1. Click the button, the cover layer appears, release the button, the cover layer disappears

2. Press and hold the button, the cover layer appears, release the button, the cover layer disappears

3. Click on the button, the cover layer, the drag button, the cover layer disappears

UIButton *btnbottom = [[UIButton alloc]initwithframe:cgrectmake (1,1,100,100)];

[Btnbottom addtarget:self Action: @selector (Buttonclicktouchdown:) Forcontrolevents:uicontroleventtouchdown];

[Btnbottom addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside];

[Self addsubview:btnbottom];

#pragma mark-

#pragma mark-the triggered event with the finger pressed (finger within the range of the button)

-(void) Buttonclicktouchdown: (UIButton *) btn

{

NSLog (@ "Finger presses the triggered event");

button click Effect

UIView *vi = [[UIView alloc]initwithframe:btn.frame];

Vi.tag = 100;

Vi.backgroundcolor = [Uicolor Graycolor];

Vi.alpha = 0.2;

[Self addsubview:vi];

}

#pragma mark-

#pragma mark-Click on the image jump link (triggers when the finger is lifted within the range of the button)

The interface jumps according to the value of the btn.btnclickurlstring

-(void) ButtonClick: (UIButton *) btn

{

NSLog (@ "Finger insd triggered event");

When your finger is lifted, remove the cover layer

For (UIView *vi in [self subviews]) {//Prevent multiple clicks from appearing multi-layered view

if (Vi.tag = = 100) {

[VI Removefromsuperview];

}

}

Click on the button to do something ....

}

#pragma mark-

#pragma mark-Click on the image jump link (triggers when the finger is dragged inside the button)

-(void) Buttonclickdraginside: (UIButton *) btn

{

NSLog (@ "Finger draginside triggered event");

When your finger is lifted, remove the cover layer

For (UIView *vi in [btn Subviews]) {

Prevent multiple clicks from appearing multi-layered view

if (Vi.tag = = 100) {

[VI Removefromsuperview];

}

}

}

Because my btn is added to a Uiscrollerview, the click on the SC scrolling will cause a bug, so when the SC is rolling, the interaction of the btn is turned off, and when the SC deceleration stops, the interactivity of the BTN is turned on.

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView

{

The interaction of the Close button when the SC is rolling (because scrolling affects the event's judgment)

if (Scrollview.tag = = 2) {

For (UIButton *btn in [ScrollView subviews])

{

NSLog (@ "Scrollviewdidscroll");

btn.userinteractionenabled = NO;

}

}

}

-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView

{

When SC stops scrolling, the interactivity of the Open button

if (Scrollview.tag = = 2) {

For (UIButton *btn in [ScrollView subviews])

{

NSLog (@ "Scrollviewdidendscrollingan");

btn.userinteractionenabled = YES;

}

}

}

Defines the effect of a button press to show the masking layer

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.