Requirement: There is a button on the page. The user requires that when the finger presses this button, a circle appears around this button. When the finger is released, the animation disappears.
I will not describe the specific page layout and event binding methods. Here, we only want to talk about the uibutton event that needs help. The method to be pressed is to bind the uibutton event.Touch down, The uibutton event to bind to the released method isTouch up insideAndTouch up outside(If you want to cancel playing the animation when your finger leaves the button, you need to bindTouch drag outsideEvent)
SpecificCodeAs follows:
1 -( Void ) Pressedevent :( ID ) Sender { // Response Method for pressing event of Button 2 Uibutton * BTN = Sender; 3 Nsarray * imgarray = [nsarray arraywithobjects: [uiimage imagenamed: @" Anim_0 " ], [Uiimage imagenamed: @" Anim_1 " ], [Uiimage imagenamed: @" Anim_2 " ], [Uiimage imagenamed: @" Anim_3 " ], Nil]; // Defines the number of frames of an animation. 4 Uiimageview * animimgview = [[uiimageview alloc] init]; // Initialize a uiimageview to play our animation frame by frame. 5 Animimgview. Frame = cgrectmake ( 0 , 0 , (Uiimage *) [imgarray objectatindex: 0 ]). Size. Width, (uiimage *) [imgarray objectatindex: 0 ]). Size. Height ); // By default, the size of each animation frame is the same. The size of the first image is taken as the size of the uiimageview. 6 Animimgview. Center = BTN. Center;// The above figure only shows the size of uiimageview. Here, we set the placement position to overlap the center of the animation and the center of the button. 7 Animimgview. Tag = 10000 ; // This setting is used to obtain the uiimageview of the playback animation from the release action triggered by the pressed button. 8 Animimgview. animationimages = imgarray; // Pass the frame-by-frame animation array to uiimageview 9 Animimgview. animationduration = 1 ; // Time used to browse all images 10 Animimgview. animationrepeatcount = 0 ; // 0 = number of loops forever animation repetitions 11 [Animimgview startanimating]; // Start playing the animation 12 [Self. View addsubview: animimgview]; // Add view to form 13 [Self. View sendsubviewtoback: animimgview]; // Move the animation playback View to the bottom of the elf. View. Pay attention to the layer occlusion problem. 14 [Animimgview release]; 15 } 16 -( Void ) Unpressedevent :( ID ) Sender { // Button release Event Response Method 17 [[Self. View viewwithtag: 10000 ] Removefromsuperview]; 18 }