iOS各种手势与UISlider的运用

#import “RootViewController.h”

@interface RootViewController ()

@property(nonatomic,retain)UIImageView *aview;

@end

@implementation RootViewController

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

{

self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

– (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view.

_aview = [[UIImageViewalloc] initWithFrame:CGRectMake(60,100, 200,
200)];

_aview.backgroundColor = [UIColorgrayColor];

[self.viewaddSubview:_aview];

//旋转

_aview.userInteractionEnabled =YES;//打开交互旋转

UIRotationGestureRecognizer *rotation =
[[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(handelRotationGesture:)];

[_aviewaddGestureRecognizer:rotation];//添加手势识别器

[rotationrelease];

//捏合

UIPinchGestureRecognizer *pinch =
[[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pingchAction:)];

[_aviewaddGestureRecognizer:pinch];

[pinchrelease];

//平移

UIPanGestureRecognizer *pan =
[[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(panAction:)];

[_aviewaddGestureRecognizer:pan];

[panrelease];

//轻扫

UISwipeGestureRecognizer *swipe =
[[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeColor:)];

[_aviewaddGestureRecognizer:swipe];

[swiperelease];

//- (void)setTitle:(NSString *)title
forSegmentAtIndex:(NSUInteger)segment;

//添加响应方式

[_asegmentaddTarget:selfaction:@selector(handelSegementControlAction:)forControlEvents:(UIControlEventValueChanged)];

_asegment.momentary =YES;//点完以后会起来,按钮(瞬间选中离开)默认为NO

[_asegmentsetEnabled:NOforSegmentAtIndex:3];//不能使用的按钮(灰色)

//滑块在设置的范围内,提供数据,滑块停留在某个位置,即得到某个数值.

UISlider *slider =
[[UISlideralloc]initWithFrame:CGRectMake(60,310,200, 30)];

[self.viewaddSubview:slider];

[sliderrelease];

slider.minimumValue =0.05;

slider.maximumValue =2;

slider.minimumTrackTintColor = [UIColorredColor];

[slider
addTarget:selfaction:@selector(handelSliderAction:)forControlEvents:(UIControlEventValueChanged)];

//播放视图动画

NSMutableArray * array =
[NSMutableArrayarrayWithCapacity:40];//存image对象

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

//图片名字 ,图片名字有误,image = nil;
2250_3650903_179fb89ae279fae-%d(被拖移).tiff

NSString *name =
[NSStringstringWithFormat:@”2250_3650903_179fb89ae279fae-%d(被拖移).tiff”,i];

//创建image

UIImage *image = [UIImageimageNamed:name];

//添加到数组中

[arrayaddObject:image];

//UIAlertView

}

_aview.animationImages = array;

//[_aview startAnimating];

_aview.animationDuration =0.5;

//_aview.animationRepeatCount = 2;//2秒播放完就没了

[_aviewstartAnimating];

//_aview.animationDuration =5;

//[_aview stopAnimating];

}

//平移

– (void)panAction:(UIPanGestureRecognizer *)pan

{

CGPoint panpoint = [pantranslationInView:pan.view];

NSLog(@”panpoint = %@”,NSStringFromCGPoint(panpoint));

pan.view.transform =CGAffineTransformMakeTranslation(panpoint.x,
panpoint.y);

}

//捏合

– (void)pingchAction:(UIPinchGestureRecognizer *)pinch

{

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

}

//轻扫

– (void)changeColor:(UISwipeGestureRecognizer *)swipe

{

_aview.backgroundColor =
[[UIColoralloc]initWithRed:arc4random()%256/255.0green:arc4random()%256/255.0
blue:arc4random()%256/255.0 alpha:1.0];

}

//旋转

– (void)handelRotationGesture:(UIRotationGestureRecognizer
*)rotationGesture

{ //修改仿射矩阵

// _aview.transform = CGAffineTransformRotate(_aview.transform,
rotationGesture.rotation);

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

// rotationGesture.rotation = 0;//旋转角度重新置为零

NSLog(@”rotation = %f”,rotationGesture.rotation);//旋转角度

}

//[Dubai]slider相应的方法

– (void)handelSliderAction:(UISlider *)slider

{

NSLog(@”%s”,__FUNCTION__);

//滑块当前的值设置为动画时间

_aview.animationDuration = slider.value;

[_aviewstartAnimating];

}

如图:

永利皇宫手机版下载 1

#import
“RootViewController.h” @interface RootViewController ()
@property(nonatomic,retain)UIImageView *aview; @end @implementation
RootViewCont…

NSLog(@”旋转”);

UIColor*random =
[UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0blue:arc4random()%256/255.0alpha:1.0];

_edgePan = [[UIScreenEdgePanGestureRecognizer
alloc]initWithTarget:selfaction:@selector(edgePanAction:)];

_pan = [[UIPanGestureRecognizer
alloc]initWithTarget:selfaction:@selector(panAction:)];

[self.view addGestureRecognizer:_edgePan];

– (void)addRotationGesture{

}

//捏合

– (void)pinchAction:(UIPinchGestureRecognizer*)pinch{

– (void)swipeAction:(UISwipeGestureRecognizer*)swipe{

– (void)addPanGesture{

}

//旋转

UITapGestureRecognizer *_tap;//单击

UIPanGestureRecognizer *_pan;//拖拽

UIPinchGestureRecognizer *_pinch;//拖拽

UIRotationGestureRecognizer *_rotation;//旋转

UISwipeGestureRecognizer *_swipe;//轻扫

UILongPressGestureRecognizer *_longpress;//长按

UIScreenEdgePanGestureRecognizer *_edgePan;//边缘滑动手势

NSLog(@”拖拽”);

//拖拽

_swipe.direction = UISwipeGestureRecognizerDirectionDown;

}

– (void)edgePanAction:(UIScreenEdgePanGestureRecognizer*)edgePan{

[_testView addGestureRecognizer:_tap];

}

@implementationViewController

NSLog(@”左边缘滑动”);

_tap.numberOfTapsRequired =1;

– (void)addTapGesture{

– (void)panAction:(UIPanGestureRecognizer*)pan{

}

– (void)tapAction:(UITapGestureRecognizer*)tap{

#pragma mark -手势

//拖拽

{

}

NSLog(@”向下轻扫”);

[superviewDidLoad];

[selfaddTapGesture];

[selfaddPanGesture];

[selfaddPinchGesture];

[selfaddRotationGesture];

[selfaddSwipeGesture];

[selfaddLongpressGesture];

[selfaddEdgePanGesture];

//手势谦让

[selfgestureHumility];

_longpress = [[UILongPressGestureRecognizer
alloc]initWithTarget:selfaction:@selector(longpressAction:)];

– (void)longpressAction:(UILongPressGestureRecognizer*)longpress{

//长按

– (void)addLongpressGesture{

_swipe = [[UISwipeGestureRecognizer
alloc]initWithTarget:selfaction:@selector(swipeAction:)];

}

#import”ViewController.h”

}

@end

#pragma mark – privatemethods//手势谦让

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

//轻扫

[_testView addGestureRecognizer:_longpress];

_tap = [[UITapGestureRecognizer
alloc]initWithTarget:selfaction:@selector(tapAction:)];

网站地图xml地图