IOS MenuViewController实现弹出菜单效果

2025-05-29 0 29

在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家。

主要说一下思路及一些核心代码贴出来,要想下载源码,请点击下载:menuviewcontroller

一个简单,效果好,比较实用的菜单弹出效果的实现,效果图:

IOS MenuViewController实现弹出菜单效果

实现方式:将self.view当前页面缩小,在当前页的上面添加一个菜单的view,即在self.view.superview添加。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78
//显示

- (void) show:(uiview*)parent

{

parentview = parent;

//先隐藏backview,table

backview.alpha = 0;

_table.alpha = 0;

//移动table

[_table settransform:cgaffinetransformmaketranslation(0, _table.frame.size.height)];

//父窗口添加本view,---这个会调用viewdidload

[parentview.superview addsubview:self.view];

//添加动画,添加到父窗口中,使之从下移动上

[uiview animatewithduration:0.3 animations:^{

//父窗口缩小

cgaffinetransform t = cgaffinetransformmakescale(0.9, 0.9);

[parentview settransform:t];

//显示backview,table

backview.alpha = 1;

_table.alpha = 1;

//移动table,cgaffinetransformidentity还原原始坐标

[_table settransform:cgaffinetransformidentity];

} completion:^(bool finished) {

}];

}

//隐藏

- (void) hide

{

//添加动画,添加到父窗口中,使之从下移动上

[uiview animatewithduration:0.3 animations:^{

//父窗口还原

cgaffinetransform t = cgaffinetransformidentity;

[parentview settransform:t];

//显示backview,table

backview.alpha = 0;

_table.alpha = 0;

//移动table

[_table settransform:cgaffinetransformmaketranslation(0, _table.frame.size.height)];

} completion:^(bool finished) {

[self.view removefromsuperview];

}];

}

- (void)viewdidload

{

[super viewdidload];

self.view.backgroundcolor = [uicolor clearcolor];

//背影黑罩

backview = [[uiview alloc]initwithframe:self.view.bounds];

backview.backgroundcolor = [uicolor colorwithred:0 green:0 blue:0 alpha:0.3];

[self.view addsubview:backview];

//算出table的cgrect

cgrect rect = self.view.bounds;

int height = _titlearray.count * 44;

rect.origin.y = rect.size.height - height;

rect.size.height = height;

_table = [[uitableview alloc]initwithframe:rect];

_table.delegate = self;

_table.datasource = self;

[self.view addsubview:_table];

}

这个菜单你可以任意自定义,我这里是一个tableview,你可以写一些有图和文字的添加上去。只需要把源代码稍改,就ok!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 IOS MenuViewController实现弹出菜单效果 https://www.kuaiidc.com/90818.html

相关文章

发表评论
暂无评论