- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章详解 iOS 系统中的视图动画由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
动画为用户界面的状态转换提供了流畅的可视化效果, 在 iOS 中大量使用了动画效果, 包括改变视图位置、 大小、 从可视化树中删除视图, 隐藏视图等。 你可以考虑用动画效果给用户提供反馈或者用来实现有趣的特效.
在 iOS 系统中, Core Animation 提供了内置的动画支持, 创建动画不需要任何绘图的代码, 你要做的只是激发指定的动画, 接下来就交给 Core Animation 来渲染, 总之, 复杂的动画只需要几行代码就可以了.
。
。
根据 iOS 视图编程指南中说明, UIView 内置支持为下列属性添加动画效果:
。
。
为了给属性的变化添加动画效果, 需要把修改这些属性的代码放到指定的动画代码段 (animation block) 中。 只有在动画代码段中修改支持动画的属性, 才能添加动画效果.
。
使用 Begin/Commit 方法做动画 。
在 iOS 3.0 以及之前的系统中, 必须使用 UIView 的类方法 beginAnimations:context: 和 commitAnimations 来定义动画代码段, 在 begin 和 commit 之间的代码会在特殊的动画线程中运行, 因此不会阻塞主线程, 比如说要切换两个视图, 代码应该是这样子的:
1
2
3
4
5
6
7
8
9
|
[UIView beginAnimations:
@"ToggleViews"
context:nil];
[UIView setAnimationDuration:1.0];
// Make the animatable changes.
firstView.alpha = 0.0;
secondView.alpha = 1.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];
|
在 Xamarin.iOS (MonoTouch) 平台下, begin/end 方法对应的绑定为:
上面的切换视图的 C# 版本代码为:
1
2
3
4
5
|
UIView.BeginAnimations(
"ToggleViews"
);
UIView.SetAnimationDuration(1.0)
this
.FirstView.Alpha = 0.0;
this
.SecondView.Alpha = 1.0;
UIView.CommitAnidations();
|
在 Begin/Commit 函数之间, 可以通过下面的方法设置动画的参数和选项:
注意: 如果不是为了支持很旧的设备, 则推荐使用下面的 lambda (block based method) 来实现动画效果, 虽然 begin/commit 还能够使用, 按照官方的说法, 对新系统来说是不推荐的了.
。
使用 lambda (block based method) 做动画 。
在 iOS 4.0 以后, 引入了代码块 (code block) 的概念, 可以使用代码块来初始化动画, 这也是在 iOS 4.0 之后苹果推荐的做法, iOS SDK 提供的 API 如下:
而在 Xamarin.iOS (MonoTouch) 平台下, 这些方法被绑定为下列方法:
还是切换视图的动画, 如果用 objective-c 的代码块来实现, 则应该是这样子的:
1
2
3
4
|
[UIView animateWithDuration:1.0 animations:^{
self.firstView.alpha = 0.0;
self.secondView.alpha = 1.0;
}];
|
如果用 C# 来实现的话, 应该是这样:
1
2
3
4
|
UIView.Animate(1.0, () => {
this
.FirstView.Alpha = 0.0f;
this
.SecondView.Alpha = 1.0f;
});
|
这样就实现了一个简单的渐变动画, 并且只能运行一次, 通常不能满足需求, 再来一个复杂点儿的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.firstView.alpha = 0.0;
}
completion:^(
BOOL
finished){
[UIView animateWithDuration:1.0
delay:1.0
options:UIViewAnimationOptionCurveEaseOut animations:^{
self.firstView.alpha = 1.0;
}
completion:nil];
}];
|
对应的 C# 代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
UIView.Animate(
1.0,
0.0,
UIViewAnimationOptions.CurveEaseIn,
() =>
this
.FirstView.Alpha = 0.0f,
() => {
UIView.Animate(
1.0,
1.0,
UIViewAnimationOptions.CurveEaseOut,
() =>
this
.FirstView.Alpha = 1.0f,
null
);
}
);
|
。
嵌套动画 。
iOS 支持嵌套的动画, 也就是说在一个动画代码段中, 可以再开始另外一个动画代码段, 而不必等当前动画完成, 嵌套的动画会同时开始运行, 默认继承原来动画的延时、 时间长度、 加速曲线等, 不过这些选项也能被覆盖。 例如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[UIView animateWithDuration:1.0
delay:1.0
options:UIViewAnimationOptionCurveEaseOut animations:^{
self.firstView.alpha = 0.0f;
// 这里开始一个新的动画
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionOverrideInheritedCurve |
UIViewAnimationOptionCurveLinear |
UIViewAnimationOptionOverrideInheritedDuration |
UIViewAnimationOptionRepeat |
UIViewAnimationOptionAutoreverse
animations:^{
[UIView setAnimationRepeatCount:2.5];
self.secondView.alpha = 0.0f;
}
completion:nil];
}
completion:nil
];
|
对应的 C# 代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
UIView.Animate(
1.0,
1.0,
UIViewAnimationOptions.CurveEaseIn,
() => {
this
.FirstView.Alpha = 0.0;
UIView.Animate(
1.0,
1.0,
UIViewAnimationOptions.OverrideInheritedCurve |
UIViewAnimationOptions.CurveLinear |
UIViewAnimationOptions.OverrideInheritedDuration |
UIViewAnimationOptions.Repeat |
UIViewAnimationOptions.Autoreverse,
() => {
UIView.SetAnimationRepeatCount(2.f);
this
.SecondView.Alpha = 0.0;
},
null
);
},
null
);
|
对于使用 Begin/Commit 方法的动画, 也可以嵌套调用 Begin/Commit 方法来实现嵌套的动画, 例如:
1
2
3
4
5
6
7
8
|
UIView.BeginAnimations(
"Animation1"
);
// Animation code goes here
// Start another animation
UIView.BeginAnimations(
"Nested animation"
);
// nested animations code goes here.
UIView.CommitAnimations();
// other code
UIView.CommitAnimations();
|
这段 C# 代码对应的 ObjC 代码很简单, 就不写出来了.
。
实现动画的自动翻转 。
当创建自动翻转指定次数的动画时, 考虑将重复次数设置为非整数值。 因为对于自动翻转的动画来说, 每次循环都是从原始值变化到目标值再变化回原始值, 如果希望动画结束之后停留在目标值, 需要将重复次数设置加上 0.5 , 否则, 动画回慢慢变回原始值, 再迅速变化到目标值, 这可能不是原来期望的动画效果.
。
。
视图切换动画可以减少修改可视化树时引起的界面上的突变, iOS 系统中大量使用了视图切换动画, 视图切换动画主要有下面两种场景:
注意: 不要把视图切换和视图控制器的切换混淆(显示一个模式对话框、将视图控制器推入导航堆栈等), 视图切换改变的仅仅是视图的可视化树, 视图控制器是不变的, 更多信息可以参考iOS视图控制器编程指南.
。
修改子视图 。
可以修改子视图的可见性用来表示当前视图的不同的状态, 看下面的两个视图切换的例子,在 iOS 4.0 之前, 需要将视图切换动画添加到 Begin/Commit 动画之间, 代码如下:
在 iOS 4.0 之后, 可以使用 transitionWithView:duration:options:animations:completion
1
2
3
4
5
6
7
|
[UIView beginAnimations:@
"toggleView"
context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDuration:1.0];
// animation goes here
self.currentView.hidden = YES;
self.swapView.hidden = NO;
[UIView commitAnimations];
|
这里只有动画部分的代码, 动画完成之后请参考 setAnimationDelegate: 方法设置并实现 UIAnimationDelegate .
。
替换子视图 。
要进行子视图的替换, 需要用到 transitionFromView:toView:duration:options:completion: 方法, 示例代码如下:
1
2
3
4
5
6
7
8
9
10
11
|
UIView *fromView = (self.displayPrimary ? self.view : self.secondView);
UIView *toView = (self.displayPrimary ? self.secondView : self.view);
UIViewAnimationOptions option = (self.displayPrimary ? UIViewAnimationOptionTransitionFlipFromRight
: UIViewAnimationOptionTransitionFlipFromLeft);
[UIView transitionFromView:fromView toView:toView duration:1.0 options:option
completion:^(
BOOL
finished) {
if
(finished) {
self.displayPrimary = !self.displayPrimary;
}
}
];
|
。
。
有了上面的知识, 链接多个动画就非常简单了:
以上就是详解 iOS 系统中的视图动画的详细内容,更多关于iOS 视图动画的资料请关注我其它相关文章! 。
原文链接:https://beginor.github.io/2013/06/22/ios-uiview-animations.html 。
最后此篇关于详解 iOS 系统中的视图动画的文章就讲到这里了,如果你想了解更多关于详解 iOS 系统中的视图动画的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!