zoukankan      html  css  js  c++  java
  • 【Objective-C学习记录】第四十天

    今天玩了几个控件和手势,让我想起了以前玩Unity的时候,拖控件,设置属性,再编写一些相应的值。

    手势

    使用手势的步骤:

    1.创建满足需求的手势,在创建时关联手势触发时的方法

    2.配置手势的相关属性

    3.将手势添加到需要执行操作的视图上面

    4.实现手势方法,当触摸发生,手势识别器识别到相对应的触摸时,就会执行关联方法

    轻拍手势

    1 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    2 //设置手势
    3 //1.触发手势的手指个数
    4 tap.numberOfTouchesRequired = 1;
    5 //2.触发手势的轻拍次数
    6 tap.numberOfTapsRequired = 2;
    7 //3.让imageView添加轻拍手势
    8 [imageView addGestureRecognizer:tap];

    轻拍手势事件

    1 - (void)tapAction:(UITapGestureRecognizer *)tap {
    2 }

    轻扫手势

    1 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@seletor(swipeAction:)];
    2 //手势方向
    3 swipe.direction = UISwipeGestureRecognizerDirectionDown;
    4 //让imageView添加轻拍手势
    5 [imageView addGestureRecognizer:swipe];

    轻扫手势事件

    1 - (void)swipeAction:(UISwipeGestureRecognizer *)swipe {
    2 }

    长按手势

    1 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    2 //长按手势触发的最短时间,默认是0.5
    3 longPress.minimunPressDuration = 3.0;
    4 //让imageView添加长按手势
    5 [imageView addGestureRecognizer:longPress];

    缩放手势

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@seletor(pinAction:)];

    缩放手势事件

     1 - (void)pinchAction:(UIPinchGestureRecognizer *)pinch {
     2      //获取要进行缩放的视图
     3      UIImageView *imageView = (UIImageView *)pinch.view;
     4      
     5      //改变imageView的形变属性
     6      //第一个参数是需要已存在的transform,第二个参数是x方向的缩放规模,第三个参数是y方向的缩放规模
     7      imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
     8      pinch.scale = 1;
     9       //或者
    10 //   imageView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
    11 }

    旋转手势

    UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateAction:)];

    旋转手势事件

     1 - (void)rotateAction:(UIRotationGestureRecognizer *)rotate {
     2      //获取想要旋转的视图
     3      UIImageView *imageView = (UIImageView *)rotate.view;
     4      
     5      //改变imageView的形变属性
     6      //回弹旋转
     7 //   imageView.transform = CGAffineTransformMakeRotation(rotate.rotation);
     8      imageView.transform = CGAffineTransformRotate(imageView.transform, rotate.rotation);
     9      rotate.rotation = 0;
    10 }

    平移手势

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

    平移手势事件

    1 - (void)panAction:(UIPanGestureRecognizer *)pan {
    2     //获取想要平移的视图
    3     UIImageView *imageView = (UIImageView *)pan.view;
    4     
    5     CGPoint p = [pan translatinInView:imageView];
    6     //改变视图的位置属性
    7     imageView.transform = CGAffineTransformTranslate(imageView.transform, p.x, p.y);
    8     [pan setTranslation:CGPointZero inView:imageView];
    9 }

    UISwitch

    1.initWithFrame:。初始化方法,这个frame的宽和高没有意义,因为系统开关控件的大小是确定的。

    2.onTintColor。设置开关开启时的颜色。

    3.tintColor。设置开关风格的颜色。

    4.thumbTintColor。设置开关按钮的颜色。

    5.onImage/offImage。设置开关开启/关闭状态时的图片(iOS 7以后不再起任何作用)。

    6.on。开关状态。

    7.setOn: animated:。手动设置开关状态,两个参数均为BOOL类型。

    UISlider

    1.initWithFrame:。初始化方法。

    2.minimumValue。设置滑块的最小值。

    3.mamximumValue。设置滑块的最大值。

    4.value。设置滑块的当前值。

    5.minimumTrackTintColor。定义划过区域的颜色。

    UISegmentedControl

    1.initWithItems:。初始化方法,参数可以为字符串、图片数组。

    2.selectedSegmentIndex。指定被选中的分段,返回被选择分段的索引值。

    3.tintColor。设置segmentedControl条的颜色。

    4.segmentedControlStyle。设置外观样式(已经不被推荐使用)。

    5.momentary。设置在点击后是否恢复原样。

    6.setTile: forSegmentAtIndex:。为指定下标的分段设置title,第一个参数为字符串,第二个参数为下标值。

    7.setImage: forSegmentAtIndex:。为指定下标的分段设置图片,第一个参数为图片,第二个参数为下标值。

    8.setEnable: forSegmentAtIndex:。设置指定索引是否可点,第一个参数为BOOL值,第二个参数为下标值。

    9.isEnableForSegmentAtIndex:。判断指定索引是否可点,返回一个BOOL值。

    UIPageControl

    1.initWithFrame:。初始化方法。

    2.numberOfPages。指定页面的个数,即点的个数。

    3.currentPage。指定pageControl的值,即选中的点。

  • 相关阅读:
    [BZOJ4480] JSOI2013 快乐的jyy
    [BZOJ4755] JSOI2016 扭动的回文串
    [BZOJ4754] JSOI2016 独特的树叶
    [BZOJ5179] JSOI2011 任务调度
    [BZOJ4320] SHOI2006 Homework
    [AT2300] Snuke Line
    [洛谷P3974] TJOI2015 组合数学
    [CF331E] Biologist
    [洛谷P4249] WC2007 剪刀石头布
    【BZOJ4548】小奇的糖果
  • 原文地址:https://www.cnblogs.com/shvier/p/5122828.html
Copyright © 2011-2022 走看看