實現IOS版的抽屜效果(點選,拖拽滑動)

2021-09-25 02:40:09 字數 2489 閱讀 2512

好像最近,看到好多android上的抽屜效果,也忍不住想要自己寫乙個。在android裡面可以用slidingdrawer,很方便的實現。ios上面就只有自己寫了。其實原理很簡單就是 uiview 的移動,和一些手勢的操作。

1//2

drawerdemo4//

5//created by zhouhaifeng on 12-3-27.6//

7//89 #import 10

11 typedef enum

12drawerviewstate;

1617 @inte***ce drawerview : uiview18

2930 - (id)initwithview:(uiview *) contentview parentview :(uiview *) parentview;

31 - (void)handlepan:(uipangesturerecognizer *)recognizer;

32 - (void)handletap:(uitapgesturerecognizer *)recognizer;

33 - (void

)transformarrow:(drawerviewstate) state;

3435 @property (nonatomic,retain) uiview *parentview;

36 @property (nonatomic,retain) uiview *contentview;

37 @property (nonatomic,retain) uiimageview *arrow;

38@property (nonatomic) drawerviewstate drawstate;

3940 @end

1//2

drawerdemo4//

5//created by zhouhaifeng on 12-3-27.6//

7//89 #import "

drawerview.h"10

11@implementation drawerview

12@synthesize contentview,parentview,drawstate;

13@synthesize arrow;

1415 - (id)initwithview:(uiview *) contentview parentview :(uiview *) parentview;

1676

return

self;77}

7879

80#pragma uigesturerecognizer handles

81/*

82* 移動處理的函式

83* @recognizer 移動手勢

84*/

85 - (void)handlepan:(uipangesturerecognizer *)recognizer else

if(self.center.y + translation.y >downpoint.y)

92else

97 [recognizer settranslation:cgpointmake(0, 0

) inview:parentview];

9899

if (recognizer.state ==uigesturerecognizerstateended) else

105109

110} completion:nil];

111112

}

113}

114115

/*116

* handletap 觸控函式

117* @recognizer uitapgesturerecognizer 觸控識別器

118*/

119 -(void) handletap:(uitapgesturerecognizer *)recognizer

120else

126130

} completion:nil];

131132

} 133

134/*

135* transformarrow 改變箭頭方向

136* state drawerviewstate 抽屜當前狀態

簡單的iOS抽屜效果

define screenw uiscreen mainscreen bounds.size.width import viewcontroller.h inte ceviewcontroller property nonatomic,strong uiview redview property n...

拖拽效果的實現原理分析

一 html5現在已經提供支援拖動和拖放的api了,所以,支援html5的瀏覽器可以不必折騰了,直接使用吧。關於html5的拖拽api 請檢視 以下摘錄一些 比較重要的物件和事件以及屬性 首先,要使元素能否能被拖拽,必須設定 draggable true 例如 只有設定draggable才可以被拖拽...

拖拽效果的實現原理分析2

上文對html5支援的瀏覽器的拖拽效果進行了分析,本文不採用任何庫,來分析下拖拽的過程 先想想我們平時拖拽是怎麼操作的,大致可以分為幾下幾個步驟 滑鼠按下,滑鼠移動,拖拽,被拖動的物件跟著走 滑鼠鬆開,物件停止,無拖動了 計算距離,拖拽的距離 滑鼠移動 對應在事件上就是 onmousedown,on...