zoukankan      html  css  js  c++  java
  • 动画的button(按下时缩小,松开时恢复)

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (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];
        return YES;
    }
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end
    #import "RootViewController.h"
    @interface RootViewController ()
    {
        CGFloat buttonScale;//比例
    }
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //初始化button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        buttonScale = 1.0;
        button.frame = CGRectMake(100, 100, 120, 60);
        [button setTitle:@"按钮" 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];
    }
    /**
     *  按钮按下时,执行的方法
     */
    - (void)buttonDownAction:(UIButton*)sender{
        CGFloat scale = buttonScale < 1.0 ? 1.0 : 0.9;
        //变小
        [UIView animateWithDuration:0.25 animations:^{
            sender.transform = CGAffineTransformMakeScale(scale, scale);
        }];
        NSLog(@"变小");
    }
    /**
     *  松开按钮时,执行的方法
     */
    - (void)buttonAction:(UIButton*)sender{
        //恢复原来的尺寸
        [UIView animateWithDuration:0.25 animations:^{
            sender.transform = CGAffineTransformMakeScale(1.0, 1.0);
        } completion:^(BOOL finished) {
            //在此执行相应操作
            NSLog(@"恢复");
        }];
    }
    
    
    @end
  • 相关阅读:
    【软剑攻城队】团队介绍发布!
    【软剑攻城队】团队简介
    耿丹计科16-1大家庭
    便捷从使用git开始
    交流从选择coding.net开始
    相识从C语言开始
    川师2016上半年软件工程助教总结
    2016年川师大软件工程本科生博客地址列表
    川师大研究生2015级现代软件工程(2016春)
    SVN:Cleanup failed to process the following paths
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5435985.html
Copyright © 2011-2022 走看看