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