1. //轻扫***
UISwipeGestureRecognizer*swip = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipChangeColor:)];
[self.view addGestureRecognizer:swip];
swip.direction= (UISwipeGestureRecognizerDirectionLeft |UISwipeGestureRecognizerDirectionRight);
UISwipeGestureRecognizer*swip2 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipChangeColor:)];
[self.view addGestureRecognizer:swip2];
swip2.direction= (UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp);
[swip2 release];
***************
- (void)swipChangeColor:(UISwipeGestureRecognizer*)swip
{
swip.view.backgroundColor = [UIColor randomColor];
}
2. //旋转
UIRotationGestureRecognizer*r = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(routation:)];
[self.view addGestureRecognizer:r];
[r release];
**************
- (void)routation:(UIRotationGestureRecognizer*)r
{
r.view.transform = CGAffineTransformMakeRotation(r.rotation);
//旋转
}
3. //缩放
UIPinchGestureRecognizer*pin = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pin:)];
[self.view addGestureRecognizer:pin];
[pin release];
- (void)pin:(UIPinchGestureRecognizer*)pin
{
//*缩放*********
pin.view.transform= CGAffineTransformMakeScale(pin.scale, pin.scale);
}
4. //偏移
UIPanGestureRecognizer*pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self.view addGestureRecognizer:pan];
[pan release];
************
- (void)pan:(UIPanGestureRecognizer*)pan
{ //偏移
CGPoint p =[pan translationInView:pan.view];//获取当前与起点的偏移量
pan.view.transform= CGAffineTransformMakeTranslation(p.x, p.y);
}
5. //UIImageView的学习使用
UIImageView*imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[self.view addSubview:imageView];
UIImageView*imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]];
//imageView2.frame= CGRectMake(0, 0, 320, 480);//默认和图片大小一样
imageView2.center= self.view.center;
imageView.backgroundColor= [UIColor blackColor];
[self.view addSubview:imageView2];
imageView2.backgroundColor= [UIColor blackColor];
[imageView2 release];
//设置图片内容
[imageView setImage:[UIImageimageWithContentsOfFile:@"/Users/lanou3g/Documents/cocos2d-x-2.2.2/samples/Javascript/Shared/tests/res/cocosgui/gui_examples/equip_1/equip/eg/1.png"]];
6. //手势识别器
//对于target..action这种设计模式,action中方法的参数始终是当前对象(tap)
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapChangeColor:)];
// tap.numberOfTapsRequired = 2;//双击可以实现
// //手势通常是与视图绑定的,用于识别这个视图上是否出现过指定的手势,如果出现过,会触发target的action事件
// [self.viewaddGestureRecognizer:tap];
// [taprelease];