button for animation (zoom out when pressed, restore on release)

Source: Internet
Author: User

#import <UIKit/UIKit.h>@interface appdelegate:uiresponder <UIApplicationDelegate>  *window; @end
#import "AppDelegate.h"#import "RootViewController.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //Override point for customization after application launch.Self.window.backgroundColor =[Uicolor Whitecolor]; Self.window.rootViewController=[[Rootviewcontroller alloc] init];    [Self.window makekeyandvisible]; returnYES;}@end
#import <UIKit/UIKit.h>@interface  rootviewcontroller:uiviewcontroller@end 
#import "RootViewController.h"@interfaceRootviewcontroller () {cgfloat buttonscale;//proportions}@end@implementationRootviewcontroller- (void) viewdidload {[Super viewdidload]; //Initialize buttonUIButton *button =[UIButton Buttonwithtype:uibuttontypecustom]; Buttonscale=1.0; Button.frame= CGRectMake ( -, -, -, -); [Button Settitle:@"Button"Forstate:0]; [Button setbackgroundimage:[uiimage imagenamed:@"Button"] Forstate:0];    [Button addtarget:self action: @selector (buttondownaction:) Forcontrolevents:uicontroleventtouchdown]; [Button addtarget:self action: @selector (buttonaction:) forcontrolevents:uicontroleventtouchupinside|Uicontroleventtouchupoutside]; [Self.view Addsubview:button];}/** * When the button is pressed, the method of execution*/- (void) Buttondownaction: (uibutton*) sender{cgfloat Scale= Buttonscale <1.0?1.0:0.9; //become smaller[UIView animatewithduration:0.25animations:^{sender.transform=Cgaffinetransformmakescale (scale, scale);    }]; NSLog (@"become smaller");}/** * The method to be executed when the button is released*/- (void) Buttonaction: (uibutton*) sender{//Restore the original size[UIView animatewithduration:0.25animations:^{sender.transform= Cgaffinetransformmakescale (1.0,1.0); } Completion:^(BOOL finished) {//perform the appropriate action hereNSLog (@"Recovery"); }];}@end

button for animation (zoom out when pressed, restore on release)

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.