IOS开发仿微信右侧弹出视图实现

2025-05-29 0 52

ios开发仿微信右侧弹出视图实现

微信首页的+号,点击之后会弹出一个更多的视图,这个视图如何实现呢?

实现该效果可能需要以下技术要点:

1.图片拉伸,通过拉伸图片的中间的较小区域来保持图片的边上的形状

2.仿射变换,用到仿射变换的缩放,平移和合并,视图动画

3.navigationbar的样式设置

实现效果,如下:

IOS开发仿微信右侧弹出视图实现

本demo图片来源微信安装包解压得到的图片

实现代码:

?

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
//

// viewcontroller.m

// appxx-微信更多工具栏

//

// created by mrbean on 15/7/27.

// copyright (c) 2015年 yangbin. all rights reserved.

//

#import "viewcontroller.h"

#define kscreenwidth self.view.bounds.size.width

@interface viewcontroller ()

@property(strong,nonatomic)uiimageview *imageview;

@end

@implementation viewcontroller

- (void)viewdidload {

[super viewdidload];

//初始化imageview

uiimage *image = [uiimage imagenamed:@"more"];

nslog(@"%f ,%f",image.size.width,image.size.height);

uiimage *stretchimage = [image resizableimagewithcapinsets:uiedgeinsetsmake(31, 36, 30, 33)];//拉伸图片

_imageview = [[uiimageview alloc]init];

_imageview.frame = cgrectmake(kscreenwidth-100, 64, 100, 150);

_imageview.image = stretchimage;

//仿射变换,矩阵变换

cgaffinetransform smaller = cgaffinetransformmakescale(0.01, 0.01);//比例缩放

cgaffinetransform rightupmove = cgaffinetransformmaketranslation(_imageview.frame.size.width/2, -_imageview.frame.size.height/2);//平移

cgaffinetransform cat = cgaffinetransformconcat(smaller, rightupmove);//合并两个矩阵变换

_imageview.transform = cat;//设置_imageview的仿射变换

_imageview.alpha = 0;//透明度

[self.view addsubview:_imageview];

_imageview.hidden = yes;

self.navigationcontroller.navigationbar.barstyle = uibarstyleblack;//设置navigationbar的样式

self.navigationcontroller.navigationbar.tintcolor = [uicolor whitecolor];//设置navigationbar字体或者镂空图的颜色

}

//点击右侧的按钮

- (ibaction)tapadd:(uibarbuttonitem *)sender

{

if (_imageview.hidden)

{

cgaffinetransform larger = cgaffinetransformmakescale(1, 1);//放大

_imageview.hidden = no;//显示视图

[uiview animatewithduration:0.2 animations:^{

_imageview.transform = larger;

_imageview.alpha = 1;

}];

}

else

{

cgaffinetransform smaller = cgaffinetransformmakescale(0.01, 0.01);//缩小

cgaffinetransform rightupmove = cgaffinetransformmaketranslation(_imageview.frame.size.width/2, -_imageview.frame.size.height/2);//移动

cgaffinetransform cat = cgaffinetransformconcat(smaller, rightupmove);//合并transform

[uiview animatewithduration:0.2 animations:^{

_imageview.transform = cat;

} completion:^(bool finished) {

_imageview.hidden = yes;

_imageview.alpha = 0;

}];

}

}

- (void)didreceivememorywarning {

[super didreceivememorywarning];

// dispose of any resources that can be recreated.

}

@end

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

收藏 (0) 打赏

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

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

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

快网idc优惠网 建站教程 IOS开发仿微信右侧弹出视图实现 https://www.kuaiidc.com/89488.html

相关文章

发表评论
暂无评论