#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)