日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
ios開發(fā)側(cè)滑菜單,安卓開發(fā)側(cè)滑菜單

Airbnb for iOS 的側(cè)滑導(dǎo)航菜單是怎么實(shí)現(xiàn)的

幾個(gè)月前曾經(jīng)粗略的閱讀過源碼,那時(shí)大致思路似乎是這樣:

主要從事網(wǎng)頁設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、響應(yīng)式網(wǎng)站開發(fā)、程序開發(fā)、微網(wǎng)站、小程序制作等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體,具備承接不同規(guī)模與類型的建設(shè)項(xiàng)目的能力。

一個(gè)RootViewController持有一個(gè)LeftMenuView和ContentView,均是RootView的SubView,并在初始化的時(shí)候用addChildViewController添加LeftMenu和Content的ViewController。

通過GestureRecognizer根據(jù)需求調(diào)整View的Alpha,然后加CGAffineTransform并Animate。左劃就縮放+平移ContentView然后調(diào)整LeftMenuView的Alpha為1,劃回來則是相反,期間還有一個(gè)側(cè)滑菜單文字的縮放特效。

ContentViewController通常是個(gè)NavController,通過LeftMenuView用Storyboard初始化根視圖控制器的。

Airbnb的側(cè)滑,在滑動(dòng)的動(dòng)畫效果里應(yīng)該還加了Transform3DMakeRotation實(shí)現(xiàn)透視效果的樣子。

個(gè)人感覺或者猜測(cè)左下角這個(gè)下三角可能是起到“重置LeftMenu和Content”的效果吧。謝邀..個(gè)人水平一般般并沒有逐行仔細(xì)閱讀源碼,如果有疏漏還請(qǐng)糾正。

iOS開發(fā)中 使用導(dǎo)航欄側(cè)滑功能實(shí)現(xiàn)pop 兩層以上的控制器該如何實(shí)現(xiàn)

1、SliderNavigation擁有三個(gè)子視圖:leftView,rightView,mainView。左右滑動(dòng)時(shí)就通過這三個(gè)視圖之間層次關(guān)系的切換來實(shí)現(xiàn)。

2、其實(shí)只有上述三個(gè)視圖完全夠了,但是又另外加上了三個(gè)屬性:leftVC,rightVC,mainVC。這樣做的目的是簡(jiǎn)化操作,同時(shí)mainVC還有記錄已展示過的視圖的任務(wù),這樣所有視圖都可以通過左右滑動(dòng)喚出導(dǎo)航欄來了。這樣每個(gè)子視圖上展示的是對(duì)應(yīng)控制器的視圖,即[leftView addSubview:leftVC.view];,其他類似。

3、當(dāng)向左滑動(dòng)時(shí),調(diào)整視圖層級(jí)關(guān)系,因?yàn)橄蜃蠡瑒?dòng)是展示右視圖,所以將leftView調(diào)整到最底層,同時(shí)讓mainView隨手指移動(dòng),這樣mainView之下的rightView就展示出來了。

4、有了上述三點(diǎn),接下來就可以通過給各個(gè)環(huán)節(jié)添加動(dòng)畫來實(shí)現(xiàn)好看的效果了。

三、接口定義

.h文件中定義好外界可以自定義的一些屬性。

首先是三個(gè)控制器

?

1

2

3

4

//左右控制器與主控制器

@property (strong, nonatomic) UIViewController *leftController;

@property (strong, nonatomic) UIViewController *rightController;

@property (strong, nonatomic) UIViewController *mainController;

其次是左右視圖的一些相關(guān)設(shè)定,有判斷點(diǎn)、便宜量、動(dòng)畫時(shí)間、能否被拉出等

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

//左右視圖被拉出以后主視圖的X方向的offset(正值)

@property (assign, nonatomic) CGFloat leftOffsetX;

@property (assign, nonatomic) CGFloat rightOffsetX;

//左右視圖被拉的過程中的判斷點(diǎn)的X值(正值)

@property (assign, nonatomic) CGFloat leftJudgeX;

@property (assign, nonatomic) CGFloat rightJudegX;

//左右視圖拉出所用的時(shí)間

@property (assign, nonatomic) NSTimeInterval leftOpenDuration;

@property (assign, nonatomic) NSTimeInterval rightOpenDuration;

//左右視圖收回時(shí)所用的時(shí)間

@property (assign, nonatomic) NSTimeInterval leftCloseDuration;

@property (assign, nonatomic) NSTimeInterval rightCloseDuration;

//左右視圖被拉出以后主視圖放縮的比例(0到1)

@property (assign, nonatomic) CGFloat rightScale;

@property (assign, nonatomic) CGFloat leftScale;

//左右視圖能否被拉出

@property (assign, nonatomic) BOOL canShowRight;

@property (assign, nonatomic) BOOL canShowLeft;

剛才也說過,mainVC要記下已經(jīng)展示過的主視圖,可以將這些加入到字典中,這樣做的作用是下次可以方便的展示出來。另外,讓每一個(gè)想展示的視圖對(duì)應(yīng)的控制器賦值給mainVC可以實(shí)現(xiàn)在所有界面中都能通過左右拉來叫出導(dǎo)航欄的功能。什么意思呢?最根部的依舊是我們封裝的sliderNavigation類,其上圖的層次依舊存在,只是改變了mainVC的值,這樣給用戶的體驗(yàn)就是,雖然主界面變了,但依然可以拉出左右導(dǎo)航欄來。

為此我們?cè)O(shè)置一個(gè)字典來保存已經(jīng)展示過的控制器

?

1

2

//用以記錄被當(dāng)做主控制器展示主視圖過的控制器

@property (strong, nonatomic) NSMutableDictionary *controllersDict;

接下來是幾個(gè)public方法聲明,將這種Manager性質(zhì)的類作為單例,暴露出其展示左右視圖的功能供按鈕控制,然后是可以讓其展示自定義類作為主界面。

?

1

2

3

4

5

6

7

8

9

//單例

+ (id)sharedInstance;

//展示左右視圖

- (void)showLeftView;

- (void)showRightView;

//展示自定義類的主視圖,參數(shù):自定義類名

- (void)showContentViewWithModel:(NSString *)className;

四、具體實(shí)現(xiàn)

首先定義一些常量

?

1

2

3

4

5

6

7

8

9

//制造反彈的動(dòng)態(tài)效果,當(dāng)通過按鈕叫出導(dǎo)航欄時(shí)有效

static const CGFloat kOpenSpringDamping = 0.65f;

static const CGFloat kOpenSpringVelocity = 0.10f;

//定義常量表示拉動(dòng)方向

typedef NS_ENUM(NSUInteger, sliderMoveDirection) {

SliderMoveDirectionLeft = 0,

SliderMoveDirectionRight,

};

然后重點(diǎn)這里講一下關(guān)鍵代碼或方法,其余的講一下思路

我們可以在初始化方法中將接口中聲明的變量賦默認(rèn)值,當(dāng)用戶沒有為這些值賦值時(shí)便可以用這些默認(rèn)值

首先我們初始化三個(gè)子視圖為屏幕大小并根據(jù)添加到sliderNavigation的子視圖中,注意添加順序:我們希望讓主視圖在最上方,所以前兩個(gè)隨意,主視圖必須最后添加。

?

1

2

3

4

5

6

7

8

9

10

11

12

- (void)_initSubviews

{

_rightView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_rightView atIndex:0];

_leftView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_leftView atIndex:1];

//主視圖要最后添加(即添加到最上面顯示)

_mainView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_mainView aboveSubview:_leftView];

}

然后我們初始化左右控制器,將左右控制器視圖分別添加到左右視圖中去。

在實(shí)現(xiàn)上述public方法“展示自定義類的主視圖”時(shí),傳入?yún)?shù)為類名,將其作為鍵來從字典中取控制器,如果沒有則以此類名新建一個(gè)控制器并加入到字典中。如果當(dāng)前主視圖上已經(jīng)有視圖,則將其移除。接著將自定義類的視圖添加到mainView上,并相應(yīng)賦值。

當(dāng)然,不要忘了關(guān)閉左右導(dǎo)航欄(因?yàn)檎故镜念愑锌赡苁峭ㄟ^左右導(dǎo)航欄點(diǎn)出來的)

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

- (void)showContentViewWithModel:(NSString *)className

{

[self _closeSliderNavigation];

UIViewController *controller = [self.controllersDict objectForKey:className];

if (controller == nil) {

Class c = NSClassFromString(className);

controller = [[c alloc] init];

[self.controllersDict setObject:controller forKey:className];

}

//如果當(dāng)前已經(jīng)有視圖被顯示,則將其取消

if (_mainView.subviews.count 0) {

[[_mainView.subviews firstObject] removeFromSuperview];

}

controller.view.frame = _mainView.frame;

[_mainView addSubview:controller.view];

self.mainController = controller;

}

接著是動(dòng)畫,這里用到的動(dòng)畫主要就是改變視圖的大小和位置,用transform即可。獲得transform的方法單獨(dú)抽出來,使用concat將大小變換矩陣和位置變換矩陣連接。接著在動(dòng)畫塊中改變主視圖的transform即可,當(dāng)然了,也可以設(shè)置上陰影效果等。需要注意的是要根據(jù)滑動(dòng)方向?qū)⑾鄳?yīng)視圖調(diào)整到最底層。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

CGAffineTransform concat = [self _transformWithMoveDirection:SliderMoveDirectionLeft];

[self.view sendSubviewToBack:_leftView];span style="white-space:pre" /span //將另一個(gè)視圖調(diào)到最下面

[self _configureViewShadowWithDirection:SliderMoveDirectionLeft]; //設(shè)置陰影

[UIView animateWithDuration:self.rightOpenDuration

delay:0

usingSpringWithDamping:kOpenSpringDampingspan style="white-space:pre" /span //彈性效果

initialSpringVelocity:kOpenSpringVelocity

options:UIViewAnimationOptionCurveLinear

animations:^{

_mainView.transform = concat;

}

completion:^(BOOL finished) {

_showingLeft = NO;

_showingRight = YES;

self.mainController.view.userInteractionEnabled = NO;

_tapGesture.enabled = YES;

}];

另一方向的雷同

最主要的還是滑動(dòng)手勢(shì)操作,也是比較麻煩的地方。不過其實(shí)思路比較清晰:獲取偏移量,在滑動(dòng)時(shí)計(jì)算出對(duì)應(yīng)的變換矩陣并設(shè)置,在滑動(dòng)結(jié)束時(shí)根據(jù)位置與判斷點(diǎn)的關(guān)系做出相應(yīng)的動(dòng)畫調(diào)整。

例如,滑動(dòng)過程中向右拉時(shí):

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

CGFloat translateX = [recognizer translationInView:_mainView].x;

translateX += currentOffsetX;

float scale = 0;

//向右拉,展示的是左視圖

if (translateX 0) {

if (self.canShowLeft == NO || self.leftController == nil) {

return;

}

//將右視圖放到底部以將左視圖顯示出來

[self.view sendSubviewToBack:_rightView];

[self _configureViewShadowWithDirection:SliderMoveDirectionRight];

if (_mainView.frame.origin.x self.leftOffsetX) {

scale = 1 - (_mainView.frame.origin.x / self.leftOffsetX) * (1 - self.leftScale);

} else {

scale = self.leftScale;

}

} else if (translateX 0) {……}

比較頭痛的十scale的計(jì)算。這里的要求是當(dāng)view從最初到最末時(shí)scale的變化為1.0到self.leftScale,因此利用數(shù)學(xué)知識(shí)推出這個(gè)公式即可。上述代碼省略了向左拉的代碼。

而在拉動(dòng)結(jié)束狀態(tài)則與左拉右拉動(dòng)畫實(shí)現(xiàn)類似。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

CGFloat translateX = [recognizer translationInView:_mainView].x;

translateX += currentOffsetX;

if (translateX self.leftJudgeX) {

if (self.canShowLeft == NO || self.leftController == nil) {

return;

}

CGAffineTransform trans = [self _transformWithMoveDirection:SliderMoveDirectionRight];

[UIView beginAnimations:nil context:nil];

_mainView.transform = trans;

[UIView commitAnimations];

_showingLeft = YES;

_showingRight = NO;

self.mainController.view.userInteractionEnabled = NO;

_tapGesture.enabled = YES;

} else if (translateX -self.rightJudgeX) {……}

ios 怎么做到每個(gè)頁面都有側(cè)滑欄

1、SliderNavigation擁有三個(gè)子視圖:leftView,rightView,mainView。左右滑動(dòng)時(shí)就通過這三個(gè)視圖之間層次關(guān)系的切換來實(shí)現(xiàn)。

2、其實(shí)只有上述三個(gè)視圖完全夠了,但是又另外加上了三個(gè)屬性:leftVC,rightVC,mainVC。這樣做的目的是簡(jiǎn)化操作,同時(shí)mainVC還有記錄已展示過的視圖的任務(wù),這樣所有視圖都可以通過左右滑動(dòng)喚出導(dǎo)航欄來了。這樣每個(gè)子視圖上展示的是對(duì)應(yīng)控制器的視圖,即[leftView addSubview:leftVC.view];,其他類似。

3、當(dāng)向左滑動(dòng)時(shí),調(diào)整視圖層級(jí)關(guān)系,因?yàn)橄蜃蠡瑒?dòng)是展示右視圖,所以將leftView調(diào)整到最底層,同時(shí)讓mainView隨手指移動(dòng),這樣mainView之下的rightView就展示出來了。

4、有了上述三點(diǎn),接下來就可以通過給各個(gè)環(huán)節(jié)添加動(dòng)畫來實(shí)現(xiàn)好看的效果了。

三、接口定義

.h文件中定義好外界可以自定義的一些屬性。

首先是三個(gè)控制器

?

1

2

3

4

//左右控制器與主控制器

@property (strong, nonatomic) UIViewController *leftController;

@property (strong, nonatomic) UIViewController *rightController;

@property (strong, nonatomic) UIViewController *mainController;

其次是左右視圖的一些相關(guān)設(shè)定,有判斷點(diǎn)、便宜量、動(dòng)畫時(shí)間、能否被拉出等

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

//左右視圖被拉出以后主視圖的X方向的offset(正值)

@property (assign, nonatomic) CGFloat leftOffsetX;

@property (assign, nonatomic) CGFloat rightOffsetX;

//左右視圖被拉的過程中的判斷點(diǎn)的X值(正值)

@property (assign, nonatomic) CGFloat leftJudgeX;

@property (assign, nonatomic) CGFloat rightJudegX;

//左右視圖拉出所用的時(shí)間

@property (assign, nonatomic) NSTimeInterval leftOpenDuration;

@property (assign, nonatomic) NSTimeInterval rightOpenDuration;

//左右視圖收回時(shí)所用的時(shí)間

@property (assign, nonatomic) NSTimeInterval leftCloseDuration;

@property (assign, nonatomic) NSTimeInterval rightCloseDuration;

//左右視圖被拉出以后主視圖放縮的比例(0到1)

@property (assign, nonatomic) CGFloat rightScale;

@property (assign, nonatomic) CGFloat leftScale;

//左右視圖能否被拉出

@property (assign, nonatomic) BOOL canShowRight;

@property (assign, nonatomic) BOOL canShowLeft;

剛才也說過,mainVC要記下已經(jīng)展示過的主視圖,可以將這些加入到字典中,這樣做的作用是下次可以方便的展示出來。另外,讓每一個(gè)想展示的視圖對(duì)應(yīng)的控制器賦值給mainVC可以實(shí)現(xiàn)在所有界面中都能通過左右拉來叫出導(dǎo)航欄的功能。什么意思呢看最根部的依舊是我們封裝的sliderNavigation類,其上圖的層次依舊存在,只是改變了mainVC的值,這樣給用戶的體驗(yàn)就是,雖然主界面變了,但依然可以拉出左右導(dǎo)航欄來。

為此我們?cè)O(shè)置一個(gè)字典來保存已經(jīng)展示過的控制器

?

1

2

//用以記錄被當(dāng)做主控制器展示主視圖過的控制器

@property (strong, nonatomic) NSMutableDictionary *controllersDict;

接下來是幾個(gè)public方法聲明,將這種Manager性質(zhì)的類作為單例,暴露出其展示左右視圖的功能供按鈕控制,然后是可以讓其展示自定義類作為主界面。

?

1

2

3

4

5

6

7

8

9

//單例

+ (id)sharedInstance;

//展示左右視圖

- (void)showLeftView;

- (void)showRightView;

//展示自定義類的主視圖,參數(shù):自定義類名

- (void)showContentViewWithModel:(NSString *)className;

四、具體實(shí)現(xiàn)

首先定義一些常量

?

1

2

3

4

5

6

7

8

9

//制造反彈的動(dòng)態(tài)效果,當(dāng)通過按鈕叫出導(dǎo)航欄時(shí)有效

static const CGFloat kOpenSpringDamping = 0.65f;

static const CGFloat kOpenSpringVelocity = 0.10f;

//定義常量表示拉動(dòng)方向

typedef NS_ENUM(NSUInteger, sliderMoveDirection) {

SliderMoveDirectionLeft = 0,

SliderMoveDirectionRight,

};

然后重點(diǎn)這里講一下關(guān)鍵代碼或方法,其余的講一下思路

我們可以在初始化方法中將接口中聲明的變量賦默認(rèn)值,當(dāng)用戶沒有為這些值賦值時(shí)便可以用這些默認(rèn)值

首先我們初始化三個(gè)子視圖為屏幕大小并根據(jù)添加到sliderNavigation的子視圖中,注意添加順序:我們希望讓主視圖在最上方,所以前兩個(gè)隨意,主視圖必須最后添加。

?

1

2

3

4

5

6

7

8

9

10

11

12

- (void)_initSubviews

{

_rightView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_rightView atIndex:0];

_leftView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_leftView atIndex:1];

//主視圖要最后添加(即添加到最上面顯示)

_mainView = [[UIView alloc] initWithFrame:self.view.bounds];

[self.view insertSubview:_mainView aboveSubview:_leftView];

}

然后我們初始化左右控制器,將左右控制器視圖分別添加到左右視圖中去。

在實(shí)現(xiàn)上述public方法逗展示自定義類的主視圖地時(shí),傳入?yún)?shù)為類名,將其作為鍵來從字典中取控制器,如果沒有則以此類名新建一個(gè)控制器并加入到字典中。如果當(dāng)前主視圖上已經(jīng)有視圖,則將其移除。接著將自定義類的視圖添加到mainView上,并相應(yīng)賦值。

當(dāng)然,不要忘了關(guān)閉左右導(dǎo)航欄(因?yàn)檎故镜念愑锌赡苁峭ㄟ^左右導(dǎo)航欄點(diǎn)出來的)

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

- (void)showContentViewWithModel:(NSString *)className

{

[self _closeSliderNavigation];

UIViewController *controller = [self.controllersDict objectForKey:className];

if (controller == nil) {

Class c = NSClassFromString(className);

controller = [[c alloc] init];

[self.controllersDict setObject:controller forKey:className];

}

//如果當(dāng)前已經(jīng)有視圖被顯示,則將其取消

if (_mainView.subviews.count 0) {

[[_mainView.subviews firstObject] removeFromSuperview];

}

controller.view.frame = _mainView.frame;

[_mainView addSubview:controller.view];

self.mainController = controller;

}

接著是動(dòng)畫,這里用到的動(dòng)畫主要就是改變視圖的大小和位置,用transform即可。獲得transform的方法單獨(dú)抽出來,使用concat將大小變換矩陣和位置變換矩陣連接。接著在動(dòng)畫塊中改變主視圖的transform即可,當(dāng)然了,也可以設(shè)置上陰影效果等。需要注意的是要根據(jù)滑動(dòng)方向?qū)⑾鄳?yīng)視圖調(diào)整到最底層。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

CGAffineTransform concat = [self _transformWithMoveDirection:SliderMoveDirectionLeft];

[self.view sendSubviewToBack:_leftView];span style="white-space:pre" /span //將另一個(gè)視圖調(diào)到最下面

[self _configureViewShadowWithDirection:SliderMoveDirectionLeft]; //設(shè)置陰影

[UIView animateWithDuration:self.rightOpenDuration

delay:0

usingSpringWithDamping:kOpenSpringDampingspan style="white-space:pre" /span //彈性效果

initialSpringVelocity:kOpenSpringVelocity

options:UIViewAnimationOptionCurveLinear

animations:^{

_mainView.transform = concat;

}

completion:^(BOOL finished) {

_showingLeft = NO;

_showingRight = YES;

self.mainController.view.userInteractionEnabled = NO;

_tapGesture.enabled = YES;

}];

另一方向的雷同

最主要的還是滑動(dòng)手勢(shì)操作,也是比較麻煩的地方。不過其實(shí)思路比較清晰:獲取偏移量,在滑動(dòng)時(shí)計(jì)算出對(duì)應(yīng)的變換矩陣并設(shè)置,在滑動(dòng)結(jié)束時(shí)根據(jù)位置與判斷點(diǎn)的關(guān)系做出相應(yīng)的動(dòng)畫調(diào)整。

例如,滑動(dòng)過程中向右拉時(shí):

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

CGFloat translateX = [recognizer translationInView:_mainView].x;

translateX += currentOffsetX;

float scale = 0;

//向右拉,展示的是左視圖

if (translateX 0) {

if (self.canShowLeft == NO || self.leftController == nil) {

return;

}

//將右視圖放到底部以將左視圖顯示出來

[self.view sendSubviewToBack:_rightView];

[self _configureViewShadowWithDirection:SliderMoveDirectionRight];

if (_mainView.frame.origin.x self.leftOffsetX) {

scale = 1 - (_mainView.frame.origin.x / self.leftOffsetX) * (1 - self.leftScale);

} else {

scale = self.leftScale;

}

} else if (translateX 0) {……}

比較頭痛的十scale的計(jì)算。這里的要求是當(dāng)view從最初到最末時(shí)scale的變化為1.0到self.leftScale,因此利用數(shù)學(xué)知識(shí)推出這個(gè)公式即可。上述代碼省略了向左拉的代碼。

而在拉動(dòng)結(jié)束狀態(tài)則與左拉右拉動(dòng)畫實(shí)現(xiàn)類似。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

CGFloat translateX = [recognizer translationInView:_mainView].x;

translateX += currentOffsetX;

if (translateX self.leftJudgeX) {

if (self.canShowLeft == NO || self.leftController == nil) {

return;

}

CGAffineTransform trans = [self _transformWithMoveDirection:SliderMoveDirectionRight];

[UIView beginAnimations:nil context:nil];

_mainView.transform = trans;

[UIView commitAnimations];

_showingLeft = YES;

_showingRight = NO;

self.mainController.view.userInteractionEnabled = NO;

_tapGesture.enabled = YES;

} else if (translateX -self.rightJudgeX) {……}

ios開發(fā)側(cè)拉菜單點(diǎn)擊手勢(shì)怎么實(shí)現(xiàn)

你是想要只能從屏幕的左邊邊緣處向右滑動(dòng)才有效么?如果是的話,加一個(gè)邊緣手勢(shì)就可以解決!如下:

- (void)viewDidLoad {

[super viewDidLoad];

UIScreenEdgePanGestureRecognizer* screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(action:)];

screenEdgePan.edges = UIRectEdgeLeft;

[self.view addGestureRecognizer:screenEdgePan];

}

-(void)action:(UIScreenEdgePanGestureRecognizer*)sender{

if (sender.edges == UIRectEdgeLeft) {

NSLog(@"正在從左邊滑動(dòng)");

switch (sender.state) {

case UIGestureRecognizerStateBegan:

NSLog(@"手勢(shì)開始");

break;

case UIGestureRecognizerStateChanged:

NSLog(@"手勢(shì)進(jìn)行中");

break;

case UIGestureRecognizerStateEnded:

NSLog(@"手勢(shì)結(jié)束");

break;

default:

break;

}

}

}


文章題目:ios開發(fā)側(cè)滑菜單,安卓開發(fā)側(cè)滑菜單
分享地址:http://www.dlmjj.cn/article/hoesdh.html