zoukankan      html  css  js  c++  java
  • 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];
    
    }
  • 相关阅读:
    The Future of Middleware and the BizTalk Roadmap
    FW: How to spawn a process that runs under the context of the impersonated user in Microsoft ASP.NET pages
    Strips illegal Xml characters
    luogu P2280 激光炸弹(二维前缀和)
    luogu P2704 炮兵阵地(经典状态压缩DP)
    SP1716 GSS3 Can you answer these queries III (线段树维护最大连续子段和)
    二分图判定、匹配问题
    C++语法综合 | 基于char*设计一个字符串类MyString
    luogu P1044 火车进出栈问题(Catalan数)
    C++设计模式 | 三种设计模式基础
  • 原文地址:https://www.cnblogs.com/jys509/p/4743463.html
Copyright © 2011-2022 走看看