• iOS UI基础-2.0按钮操作与形变


    按钮状态

    1.normal:默认状态 Default
    对应的枚举常量:UIControlStateNormal
     
    2.highlighted(高亮状态)
    按钮被按下去的时候(未松开)
    对应的枚举常量:UIControlStateHighlighted
     
    3.disabled(失效状态,不可用状态)
    如果enable属性为NO,就是处于disabled状态,代表按钮不可被点击
    对应的枚举常量:UIControlStateDisabled
     
    上下左右操作,思路:
    1.给每个操作增加一个Tag值
    2.根据tag值,来判断点击的是那个button
    /**
     frame属性,通常用于实例化控件,指定初始位置
     
     如果需要改变控件位置,可以使用center属性
     如果需要改变控件大小,可以使用bounds属性
     */
    - (IBAction)move:(UIButton *)button
    {
        // 提示,也可以通过center修改位置,可以课后练习
        CGPoint center = self.iconButton.center;
        
        // 2. 根据按钮的类型tag,判断移动的方向,再修改结构体的成员
        // magic number魔法数字
        switch (button.tag) {
            case kMovingDirTop:        //
                center.y -= 10.0f;
                break;
            case kMovingDirBottom:        //
                center.y += 10.0f;
                break;
            case kMovingDirLeft:        //
                center.x -= 10.0f;
                break;
            case kMovingDirRight:        //
                center.x += 10.0f;
                break;
        }
        
        // 3. 重新为对象的结构体属性赋值
        self.iconButton.center = center;
        
        NSLog(@"%@", NSStringFromCGRect(self.iconButton.frame));
    }

    transform使用

    1.位置移动
    // 向上移动
    - (IBAction)top:(UIButton *)sender {
        // 1.transform是相对于初始状态的一种状态,但是其实self.head.frame.origin的值已经被改变了
    //    self.head.transform = CGAffineTransformMakeTranslation(0, self.head.transform.ty - 20);
       
        // 2.使用原有的transform生成新的transform
        self.head.transform = CGAffineTransformTranslate(self.head.transform, 0, -20);
    }

    2.尺寸变化

     // 缩小
     - (IBAction)narrow:(UIButton *)sender {
        // 缩小20%
         self.head.transform = CGAffineTransformScale(self.head.transform, 0.8, 0.8);
     }

    3.旋转

    /** 旋转 */
    - (IBAction)rotate:(UIButton *)button
    {
        // 在OC的开发中,关于角度统一都使用弧度值,逆时针是负值,顺时针是正值
        // 180° = M_PI
        CGFloat angle = (button.tag) ? -M_PI_4 : M_PI_4;
        
        [UIView beginAnimations:nil context:nil];
        self.iconButton.transform = CGAffineTransformRotate(self.iconButton.transform, angle);
        [UIView commitAnimations];
    
    }
  • 相关阅读:
    MySQL日期数据类型、时间类型使用总结
    mybatis中的mapper接口文件以及example类的实例函数以及详解
    IDEA 的快捷键简单使用
    Enum强制转换
    保存信息到配置文件
    通过配置文件判断程序首次启动
    StackPanel Binding
    RadGridView样式设置与Binding
    虚拟键盘输入之回车事件绑定与鼠标点击事件绑定
    数据库基础之-范式
  • 原文地址:https://www.cnblogs.com/jys509/p/4743463.html
Copyright © 2020-2023  润新知