UIImageView 7種手勢基本介紹

2021-06-22 10:26:34 字數 3455 閱讀 7744

//uiimageview的使用

uiimageview *imageview = [[uiimageview alloc]initwithframe:cgrectmake(0, 20, 280, 300)];

[imageview setbackgroundcolor:[uicolor redcolor]];

[self.view addsubview:imageview];

[imageview release];

//利用產生乙個uiimage物件

//把這張載入到相框(uiimageview)

imageview.image = image;

//    imageview.image = image1;

//手勢識別器

//1.輕拍手勢

//手勢需要在定義是繫結乙個觸發方法(sel)

uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapaction:)];

//  輕拍的設定

//  需要輕拍兩次才能響應事件

tap.numberoftapsrequired = 2;

//  手指的個數

tap.numberoftouchesrequired = 2;

//給view新增乙個手勢

[imageview addgesturerecognizer:tap];

[tap release];

//2.長按手勢(longpress)

uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc]initwithtarget:self action:@selector(longpressaction:)];

[imageview addgesturerecognizer:longpress];

[longpress release];

//長按觸發方法所需要的事件

longpress.minimumpressduration = 0.5;

// 長按時允許使用者移動手指的距離

longpress.allowablemovement = 100;

//3. 清掃手勢(swipe)

uiswipegesturerecognizer *swipe = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipeaction:)];

//設定清掃的方向

swipe.direction = uiswipegesturerecognizerdirectionleft | uiswipegesturerecognizerdirectionright | uiswipegesturerecognizerdirectionup | uiswipegesturerecognizerdirectiondown;

[imageview addgesturerecognizer:swipe];

[swipe release];

//4.拖拽手勢(pan)

uipangesturerecognizer *pan = [[uipangesturerecognizer alloc]initwithtarget:self action:@selector(panaction:)];

[imageview addgesturerecognizer:pan];

[pan release];

//5.旋轉手勢(ratation)

uirotationgesturerecognizer *rotation = [[uirotationgesturerecognizer alloc]initwithtarget:self action:@selector(rotationaction:)];

[imageview addgesturerecognizer:rotation];

[rotation release];

//6.捏合手勢(pinch)

uipinchgesturerecognizer *pinch = [[uipinchgesturerecognizer alloc]initwithtarget:self action:@selector(pinchaction:)];

[imageview addgesturerecognizer:pinch];

[pinch release];

//7.螢幕邊緣拖拽

uiscreenedgepangesturerecognizer *screenedgepan = [[uiscreenedgepangesturerecognizer alloc]initwithtarget:self action:@selector(screenpan:)];

//設定螢幕邊緣拖拽的方向

screenedgepan.edges = uirectedgeleft;

[imageview addgesturerecognizer:screenedgepan];

[screenedgepan release];

//將uiimageview的使用者互動開啟,

使他能響應輕拍

[imageview setuserinteractionenabled:yes];

} // 輕拍的觸發方法

- (void)tapaction:(uitapgesturerecognizer *)tap

// 長按的觸發方法

- (void)longpressaction:(uilongpressgesturerecognizer *)longpress

} //清掃的觸發方式

- (void)swipeaction:(uiswipegesturerecognizer *)swipe

//拖拽的觸發方法

- (void)panaction:(uipangesturerecognizer *)pan

//旋轉的觸發方法

- (void)rotationaction:(uirotationgesturerecognizer *)rotation

//捏合的觸發方法

- (void)pinchaction:(uipinchgesturerecognizer *)pinch

//螢幕邊緣拖拽

- (void)screenpan:(uiscreenedgepangesturerecognizer *)screenpan

UIImageView 的三種使用方式

初始化 uiimageview imageview uiimageview alloc initwithframe cgrectmake 100,200,120,120 需要設定 uiimage 第一種 imageview setimage uiimage imagenamed 1.jpeg 第二種...

Swift 七種手勢

直接將手勢拖到viewcontroller的新增手勢的方法 將手勢的載體放入viewcontroller iboutlet weak vartaplabel uilabel iboutlet weak varpinchlabel uilabel iboutlet weak varrotationla...

iOS中七種手勢

ios中提供了7種手勢,其原理都是對touchesbegin,touchesended,touchesmoved,touchescanceled 四種方法的封裝,繼承於uigesturerecognizer類,這七種方法分別是 1.輕拍手勢uitapgesturerecognizer 2.長按手勢u...