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
  • 相关阅读:
    安卓机-华为安装charles证书
    sed替换文件内容
    升级php5.3.10到php5.6.30
    js 判断设备
    element-ui框架富文本编辑器
    git从主分支上拉取新分支以及提交代码、合并到主分支
    前端项目初始化
    vue路由点击第二次时报错
    js 数组sort方法根据数组中对象的某一个属性值进行排序
    去除一个数组中与另一个数组中的相同元素
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5435985.html
Copyright © 2011-2022 走看看