8-26 UIControl UIGestureRecognizer 控件

来源:互联网 发布:淘宝马切达是什么牌子 编辑:程序博客网 时间:2024/06/10 21:27

UIControl,一个交互类

UIImageView无自带的监听事件,可用UIControl来帮助实现监听

UIImageView的交互属性一定要手动打开,默认是关闭的

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"01"]];    //交互属性打开    imageView.userInteractionEnabled = YES;    [imageView setBounds:CGRectMake(0, 0, 40, 40)];    [imageView setCenter:CGPointMake(160, 240)];    [self.view addSubview:imageView];        UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];    [control addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];    //将control添加到imageView上    [imageView addSubview:control];


UIGestureRecognizer,手势控制抽象类


UITapGestureRecognizer:点击手势

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];    //点击的次数    tap.numberOfTapsRequired = 2;    //手指数    tap.numberOfTouchesRequired = 2;    //视图控件    //对视图添加点击手势    [self.view addGestureRecognizer:tap];

UILongPressGestureRecognizer:长按手势

    UILongPressGestureRecognizer *lon = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];    //最短时间    lon.minimumPressDuration = 3;    //响应之前可移动的距离    lon.allowableMovement = 240;    [self.view addGestureRecognizer:lon];

UIRotationGestureRecognizer:旋转手势


     UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];        [self.view addGestureRecognizer:rotation];


属性:

rotation                旋转的角度(弧度)

    velocity                 角速度


UISwipeGestureRecognizer:滑动手势


     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];    swipe.direction = UISwipeGestureRecognizerDirectionLeft;    [self.view addGestureRecognizer:swipe];


属性:

direction                滑向的方向设置

   numberOfTouchesRequired 手指数


UIPinchGestureRecognizer:捏合手势

    

     UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];        [self.view addGestureRecognizer:pinch];


属性:

scale 缩放比例

     velocity        缩放速率


UIPanGestureRecognizer:拖动手势


     UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)];        [self.view addGestureRecognizer:pan];


属性:

minimumNumberOfTouches    最小手指数

maximumNumberOfTouches    最大手指数

translationInView:  获取坐标的偏移量



控件


UISegmentedControl


    NSArray *array = @[@"春", @"夏", @"秋", @"冬"];    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:array];    [segment setFrame:CGRectMake(100, 100, 200, 40)];    segment.momentary = YES;    [self.view addSubview:segment];

属性:

可以使用字符串和图片初始化

      momentary        没有选中效果

numberOfSegments 分段的数量

  apportionsSegmentWidthsByContent  根据内容调整宽度

selectedSegmentIndex  被选中的分段


UISlider


    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 100, 200, 40)];    slider.value = 0.5;    //slider.minimumValueImage = [UIImage imageNamed:@"01"];    slider.minimumTrackTintColor = [UIColor redColor];    slider.thumbTintColor = [UIColor brownColor];    [slider setThumbImage:[UIImage imageNamed:@"01"] forState:UIControlStateHighlighted];    [self.view addSubview:slider];

属性:

   value            当前的值

minimumValue     最小值

  maximumValue     最大值

minimumValueImage左图片

      maximumValueImage右图片

        continuous       是否连续发送值改变的结果

        minimumTrackTintColor  左端进度条的颜色

      maximumTrackTintColor  右端进度调的颜色

        thumbTintColor         滑块颜色


UIProgressView


    UIProgressView *progress = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 100, 200, 40)];    progress.progress = 0.5;    //progress.progressViewStyle = UIProgressViewStyleBar;    progress.progressTintColor = [UIColor redColor];    [self.view addSubview:progress];


属性:

 progress         进度值

progressTintColor 进度颜色

trackTintColor   轨道颜色

   progressImage    进度图片


UISwitch

    

    UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 60, 40)];    sw.thumbTintColor = [UIColor redColor];    sw.onImage = [UIImage imageNamed:@"01"];    sw.on = YES;    [self.view addSubview:sw];


属性:

 on     开关的状态

 onTintColor      开的颜色

   tintColor        关的颜色

thumbTintColor   滑块颜色

onImage          开的图片(7及以后无效果)

   offImage 关的图片


UIActivityIndicatorView

    

    ait = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 100, 40, 40)];    [ait startAnimating];    ait.backgroundColor = [UIColor blackColor];    ait.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;    ait.color = [UIColor redColor];    [self.view addSubview:ait];


属性:

    hidesWhenStopped    是否在动画停止时隐藏

color               控件颜色

startAnimating      开始

  stopAnimating       停止

     isAnimating       是否在进行


[[UIApplicationsharedApplication] setNetworkActivityIndicatorVisible:(BOOL)]   设置状态条指示器的状态


UIStepper


   UIStepper *step = [[UIStepperalloc] initWithFrame:CGRectMake(100,100, 80, 40)];

    [self.viewaddSubview:step];


属性:

  value            步进器当前的值

minimumValue        最小值

maximumValue        最大值

stepValue           每一步的值

continuous          是否持续发送值的改变

      autorepeat     按住不松,值是否叠加

wraps     是否循环


setIncrementImage:forState: 设置加号的图片

setDecrementImage:forState: 设置减号的图片


总结:今天讲了太多的控件,只是结合头文件讲的,没有太多的实例。


0 0