手势移动 和UIImageView的动画

//

//  ImageViewController.m

//  TestImageView

//

//  Created by lanou on 12-12-19.

//  Copyright (c) 2012 lanou. All rights reserved.

//

 

#import "ImageViewController.h"

 

@interfaceImageViewController ()

 

@end

 

@implementation ImageViewController

-(void)dealloc

{

    [_imageViewrelease];

    [super dealloc];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

-(void)loadView

{

    self.view = [[[UIViewalloc]initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];

    //创建一个imageView对象

    //    UIImage *image = [UIImage imageNamed:@"lanou.png"];

    //    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];

    //    imageView.userInteractionEnabled = YES;

    //    imageView.hidden = YES;

    //    在一定事件内关闭事件传递:应用程序调用

    //    UIApplicationbeginlgnoringInteractionEvents

    //    endlgnoringInteractionEvents

    

    //    imageView.frame = CGRectMake(0,100, 320, 320);

    //    [self.view addSubview:imageView];

    //    imageView.userInteractionEnabled = YES;

    //点击

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

    //    tap.numberOfTapsRequired = 2;

    //    [imageView addGestureRecognizer:tap];

    //    [tap release];

    

    //捏合

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

    //    [imageView addGestureRecognizer:pinch];

    

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

    //    [imageView addGestureRecognizer:rotate];

    

    

    //参数数组里面只能放image NSString

    

    //    NSArray *arr = [NSArray arrayWithObjects:@"",@"",@"",nil];

    //    UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:arr];

    //    seg.selectedSegmentIndex = 1;

    //    seg.frame = CGRectMake(30, 100, 200, 30);

    //    seg.segmentedControlStyle = UISegmentedControlStyleBar;

    //    seg.tintColor = [UIColor greenColor];

    //    [seg addTarget:self action:@selector(choose:) forControlEvents:UIControlEventValueChanged];

    //    [self.view addSubview:seg];

    //    [seg release];

    //    [imageView release];

    

    

    //下午

    _imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(120, 175, 79, 106)];

    NSMutableArray *images = [NSMutableArrayarrayWithCapacity:1];

    for (int i=1; i<8; i++) {

        NSString *name = [NSStringstringWithFormat:@"huoju_%d.tiff",i];

        UIImage *image = [UIImage imageNamed:name];

        [images addObject:image];

    }

    _imageView.animationImages = images;

    _imageView.animationDuration = 10.0;

    _imageView.animationRepeatCount = 100;

    [_imageViewstartAnimating];

    [self.viewaddSubview:_imageView];

    

    UISlider *s = [[UISlideralloc]initWithFrame:CGRectMake(-150, 170, 320, 30)];

    s.maximumValue = 3;

    s.minimumValue = 1;

    CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI/2);

    s.transform=rotation;

    [s setMinimumTrackTintColor:[UIColoryellowColor]];

    [s setMaximumTrackTintColor:[UIColorredColor]];

    [s setThumbTintColor:[UIColorblueColor]];

    s.value = 1;

    [s addTarget:selfaction:@selector(change:) forControlEvents:UIControlEventValueChanged];

    [self.viewaddSubview:s];

    [s release];

}

-(void)choose:(UISegmentedControl *)seg

{

    NSLog(@"%d",seg.selectedSegmentIndex);

}

 

-(void)change:(UISlider *)slid

{

    if (_imageView.isAnimating)

    {

        [_imageViewstopAnimating];

    }

    _imageView.animationDuration = slid.value;

    [_imageViewstartAnimating];

}

 

//点击

-(void)tap:(UITapGestureRecognizer *)tap

{

    self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];

    NSLog(@"tap");

}

//缩放

-(void)tap2:(UIPinchGestureRecognizer *)pinch

{

    float scale = [pinch scale];

    CGRect bounds = [[pinch view]bounds];

    bounds.size.width *= scale;

    bounds.size.height *=scale;

    [pinch view].bounds = bounds;

    pinch.scale = 1;

}

//旋转

-(void)rotate:(UIRotationGestureRecognizer *)pinch

{

    [pinch view].transform = CGAffineTransformMakeRotation(pinch.rotation);

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

posted @ 2012-12-19 19:59  言程序  阅读(1228)  评论(0)    收藏  举报