- (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));
//更改view的transform
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.
}