服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - iOS开发中常用的各种动画、页面切面效果

iOS开发中常用的各种动画、页面切面效果

2021-01-15 16:06jerrylsxu IOS

这篇文章主要介绍了iOS开发中常用的各种动画、页面切面效果 的相关资料,需要的朋友可以参考下

今天主要用到的动画类是calayer下的catransition至于各种动画类中如何继承的在这也不做赘述,网上的资料是一抓一大把。好废话少说切入今天的正题。

  一.封装动画方法

    1.用catransition实现动画的封装方法如下,每句代码是何意思,请看注释之。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma catransition动画实现
- (void) transitionwithtype:(nsstring *) type withsubtype:(nsstring *) subtype forview : (uiview *) view
{
//创建catransition对象
catransition *animation = [catransition animation];
//设置运动时间
animation.duration = duration;
//设置运动type
animation.type = type;
if (subtype != nil) {
//设置子类
animation.subtype = subtype;
}
//设置运动速度
animation.timingfunction = uiviewanimationoptioncurveeaseinout;
[view.layer addanimation:animation forkey:@"animation"];
}

    代码说明:

      catransition常用的属性如下:

        duration:设置动画时间

        type:稍后下面会详细的介绍运动类型

        subtype:和type匹配使用,指定运动的方向,下面也会详细介绍

        timingfunction :动画的运动轨迹,用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是

                 均匀变化(相同时间变化量相同)还是先快后慢,先慢后快还是先慢再快再慢.    

               * 动画的开始与结束的快慢,有五个预置分别为(下同):

                   * kcamediatimingfunctionlinear 线性,即匀速

                   * kcamediatimingfunctioneasein 先慢后快

                   * kcamediatimingfunctioneaseout 先快后慢

                  * kcamediatimingfunctioneaseineaseout 先慢后快再慢

                  * kcamediatimingfunctiondefault 实际效果是动画中间比较快.

   2.用uiview的block回调实现动画的代码封装 

?
1
2
3
4
5
6
7
8
#pragma uiview实现动画
- (void) animationwithview : (uiview *)view withanimationtransition : (uiviewanimationtransition) transition
{
[uiview animatewithduration:duration animations:^{
[uiview setanimationcurve:uiviewanimationcurveeaseinout];
[uiview setanimationtransition:transition forview:view cache:yes];
}];
}

    3.改变view的背景图,便于切换时观察

?
1
2
3
4
5
#pragma 给view添加背景图
-(void)addbgimagewithimagename:(nsstring *) imagename
{
self.view.backgroundcolor = [uicolor colorwithpatternimage:[uiimage imagenamed:imagename]];
}

  二.调用上面的方法实现我们想要的动画

    1.我们在view上添加多个button,给不同的button设置不同的tag值,然后再viewcontroller中绑定同一个方法,点击不同的button实现不同的页面切换效果。storyboard上的控件效果如下图所示:

iOS开发中常用的各种动画、页面切面效果

    2.下面我们就开始编写点击button要回调的方法

      (1).定义枚举来标示按钮所对应的动画类型,代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
typedef enum : nsuinteger {
fade = , //淡入淡出
push, //推挤
reveal, //揭开
movein, //覆盖
cube, //立方体
suckeffect, //吮吸
oglflip, //翻转
rippleeffect, //波纹
pagecurl, //翻页
pageuncurl, //反翻页
camerairishollowopen, //开镜头
camerairishollowclose, //关镜头
curldown, //下翻页
curlup, //上翻页
flipfromleft, //左翻转
flipfromright, //右翻转
} animationtype;

    (2),获取button的tag值:

?
1
2
uibutton *button = sender;
animationtype animationtype = button.tag;

    (3).每次点击button都改变subtype的值,包括上,左,下,右

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
nsstring *subtypestring;
switch (_subtype) {
case :
subtypestring = kcatransitionfromleft;
break;
case :
subtypestring = kcatransitionfrombottom;
break;
case :
subtypestring = kcatransitionfromright;
break;
case :
subtypestring = kcatransitionfromtop;
break;
default:
break;
}
_subtype += ;
if (_subtype > ) {
_subtype = ;
}

    (4),通过switch结合上边的枚举来判断是那个按钮点击的

?
1
2
3
4
switch (animationtype)
{
//各种case,此处代码下面会给出
}

   3.调用我们封装的运动方法,来实现动画效果

    (1),淡化效果

?
1
2
3
case fade:
[self transitionwithtype:kcatransitionfade withsubtype:subtypestring forview:self.view];
break; 

    (2).push效果

?
1
2
3
case push:
[self transitionwithtype:kcatransitionpush withsubtype:subtypestring forview:self.view];
break;

     效果如下:

 iOS开发中常用的各种动画、页面切面效果

    (3).揭开效果:

?
1
2
3
case reveal:
[self transitionwithtype:kcatransitionreveal withsubtype:subtypestring forview:self.view];
break;

    效果图如下:

  iOS开发中常用的各种动画、页面切面效果

    (4).覆盖效果

?
1
2
3
case movein:
[self transitionwithtype:kcatransitionmovein withsubtype:subtypestring forview:self.view];
break;

      效果图如下:

iOS开发中常用的各种动画、页面切面效果

   (5).立方体效果

?
1
2
3
case cube:
[self transitionwithtype:@"cube" withsubtype:subtypestring forview:self.view];
break;

    效果如下:

   iOS开发中常用的各种动画、页面切面效果

    (6).吮吸效果

?
1
2
3
case suckeffect:
[self transitionwithtype:@"suckeffect" withsubtype:subtypestring forview:self.view];
break;

      效果如下:

iOS开发中常用的各种动画、页面切面效果

    (7).翻转效果

?
1
2
3
case oglflip:
[self transitionwithtype:@"oglflip" withsubtype:subtypestring forview:self.view];
break;

    效果图如下:

iOS开发中常用的各种动画、页面切面效果

    8.波纹效果

?
1
2
3
case rippleeffect:
[self transitionwithtype:@"rippleeffect" withsubtype:subtypestring forview:self.view];
break;  

 iOS开发中常用的各种动画、页面切面效果

    (9).翻页和反翻页效果

?
1
2
3
4
5
6
case pagecurl:
[self transitionwithtype:@"pagecurl" withsubtype:subtypestring forview:self.view];
break;
case pageuncurl:
[self transitionwithtype:@"pageuncurl" withsubtype:subtypestring forview:self.view];
break;

iOS开发中常用的各种动画、页面切面效果  iOS开发中常用的各种动画、页面切面效果

    (10).相机打开效果

?
1
2
3
4
5
6
case camerairishollowopen:
[self transitionwithtype:@"camerairishollowopen" withsubtype:subtypestring forview:self.view];
break;
case camerairishollowclose:
[self transitionwithtype:@"camerairishollowclose" withsubtype:subtypestring forview:self.view];
break;

iOS开发中常用的各种动画、页面切面效果

  (11),调用上面封装的第二个动画方法

?
1
2
3
4
5
6
7
8
9
10
11
12
case curldown:
[self animationwithview:self.view withanimationtransition:uiviewanimationtransitioncurldown];
break;
case curlup:
[self animationwithview:self.view withanimationtransition:uiviewanimationtransitioncurlup];
break;
case flipfromleft:
[self animationwithview:self.view withanimationtransition:uiviewanimationtransitionflipfromleft];
break;
case flipfromright:
[self animationwithview:self.view withanimationtransition:uiviewanimationtransitionflipfromright];
break;

以上内容是针对ios开发中常用的各种动画、页面切面效果的相关介绍,希望对大家有所帮助!

延伸 · 阅读

精彩推荐
  • IOS详解iOS中多个网络请求的同步问题总结

    详解iOS中多个网络请求的同步问题总结

    这篇文章主要介绍了详解iOS中多个网络请求的同步问题总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    liang199111302021-03-15
  • IOSiOS自定义UICollectionViewFlowLayout实现图片浏览效果

    iOS自定义UICollectionViewFlowLayout实现图片浏览效果

    这篇文章主要介绍了iOS自定义UICollectionViewFlowLayout实现图片浏览效果的相关资料,需要的朋友可以参考下...

    jiangamh8882021-01-11
  • IOSiOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)

    iOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和

    这篇文章主要介绍了iOS中滑动控制屏幕亮度和系统音量(附加AVAudioPlayer基本用法和Masonry简单使用)的相关资料,需要的朋友可以参考下...

    CodingFire13652021-02-26
  • IOSiOS中MD5加密算法的介绍和使用

    iOS中MD5加密算法的介绍和使用

    MD5加密是最常用的加密方法之一,是从一段字符串中通过相应特征生成一段32位的数字字母混合码。对输入信息生成唯一的128位散列值(32个字符)。这篇文...

    LYSNote5432021-02-04
  • IOSiOS开发技巧之状态栏字体颜色的设置方法

    iOS开发技巧之状态栏字体颜色的设置方法

    有时候我们需要根据不同的背景修改状态栏字体的颜色,下面这篇文章主要给大家介绍了关于iOS开发技巧之状态栏字体颜色的设置方法,文中通过示例代码...

    梦想家-mxj8922021-05-10
  • IOSiOS中UILabel实现长按复制功能实例代码

    iOS中UILabel实现长按复制功能实例代码

    在iOS开发过程中,有时候会用到UILabel展示的内容,那么就设计到点击UILabel复制它上面展示的内容的功能,也就是Label长按复制功能,下面这篇文章主要给大...

    devilx12792021-04-02
  • IOSiOS实现控制屏幕常亮不变暗的方法示例

    iOS实现控制屏幕常亮不变暗的方法示例

    最近在工作中遇到了要将iOS屏幕保持常亮的需求,所以下面这篇文章主要给大家介绍了关于利用iOS如何实现控制屏幕常亮不变暗的方法,文中给出了详细的...

    随风13332021-04-02
  • IOSiOS开发之视图切换

    iOS开发之视图切换

    在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单。在iOS开发中常用的视图切换有三种,今天我们将...

    执着丶执念5272021-01-16