小寒假第十五天总结 UIImageView UIGesture

- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:1];

    for (int i = 2; i < 9; i++) {

        NSString *fileName = [NSString stringWithFormat:@"IMG_08%d.JPG",i];

        UIImage *aImage = [UIImage imageNamed:fileName];

        [imageArray addObject:aImage];

    }

    

    

    

    //它相当于一个相框,专门用于显示图片,可以存放一个图片或一组图片  uiimage图片对象

//    UIImage *aImage = [UIImage imageNamed:@"屏幕快照 2015-02-22 下午3.33.28.png"];

    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];

    //改播放时间

    _imageView.animationDuration = 7;

//    imageView.image = aImage;

    _imageView.animationImages = imageArray;

    

    [self.view addSubview:_imageView];

    [_imageView release];

    //开始播放动画

    [_imageView startAnimating];

    

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 350, 280, 100)];

    [slider addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];

    slider.minimumTrackTintColor = [UIColor redColor];

    slider.maximumTrackTintColor = [UIColor greenColor];

    slider.minimumValue = 7;

    slider.maximumValue = 10;

    [self.view addSubview:slider];

    [slider release];

}



- (void)changeValue:(UISlider *)slider

{

    //更改动画时长

    _imageView.animationDuration = slider.value;

    //手动启动动画

    [_imageView startAnimating];

    NSLog(@"changeValue! = %f", slider.value);

}




@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(20, 100, 280, 280)];

    aView.backgroundColor = [UIColor greenColor];

    [self.view addSubview:aView];

    [aView release];

    //轻拍手势

//    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackGroundColoe:)];

//    tapGesture.numberOfTapsRequired = 2;//需要点2

//    tapGesture.numberOfTouchesRequired = 2;//需要两个手指

//    [aView addGestureRecognizer:tapGesture];// aview release了么?

//    [tapGesture release];

    


    //长按手势

//    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackGroundColoe:)];

//    [aView addGestureRecognizer:longPress];

//    longPress.minimumPressDuration = 2;// 最小按的时间


    //轻扫手势

//    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(changeViewBackGroundColoe:)];

//    

//    swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;

//    [aView addGestureRecognizer:swipeGesture];

//    [swipeGesture release];

    

    //拖动手势

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

//    [aView addGestureRecognizer:panGesture];

//    [panGesture release];


    //捏合手势

//    UIPinchGestureRecognizer *pinchGestrure = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

//    [aView addGestureRecognizer:pinchGestrure];

//    [pinchGestrure release];


    

    //旋转手势

    UIRotationGestureRecognizer *routationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

    [aView addGestureRecognizer:routationGesture];

    [routationGesture release];

    

    


}


- (void)rotationAction:(UIRotationGestureRecognizer *)routation

{

    NSLog(@"rotation = %f", routation.rotation);

    //view旋转

    routation.view.transform = CGAffineTransformMakeRotation(routation.rotation);

}





- (void)pinchAction:(UIPinchGestureRecognizer *)pinch

{

    NSLog(@"scale = %f", pinch.scale);

    //view缩放

    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);

}





- (void)panAction:(UIPanGestureRecognizer *)panGesTure

{

    //基于你手指起始点的偏移量

    CGPoint offsetPoint = [panGesTure translationInView:panGesTure.view];

    NSLog(@"offset point = %@", NSStringFromCGPoint(offsetPoint));

    //更改viewtransform

    panGesTure.view.transform = CGAffineTransformMakeTranslation(offsetPoint.x, offsetPoint.y);

}






- (void)changeViewBackGroundColoe:(UISwipeGestureRecognizer *)tap

{

    UIView *aView = tap.view;

    aView.backgroundColor = [UIColor colorWithRed:(arc4random() % 256) / 255.0 green:(arc4random() % 256) / 255.0  blue:arc4random() % 256 / 255 alpha:1.0];

    NSLog(@"tap");

}







- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值