<原>UIView 动画总结
在早期版本中
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2.0]; [UIView setAnimationDelegate:self]; //这里添加一些 视图的属性变化,比如frame alpha 等等 就会动画的改变这些属性 [UIView commitAnimations];
可以动画改变的属性有 frame bounds center transform(旋转) alpha(透明度) bacgroundColor
contentStretch(内容拉伸)
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2.0]; [UIView setAnimationDelegate:self]; //这一句设置 视图的 切换动画效果,此时的self.view一定要是 一个盛放视图的容器 //也就是说 是父视图 [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; //此处添加切换视图的动作 // 可以是这样 [self.view addSubView:view1]; // 也可以是 [view2 removeFromSuperview]; view2的 superView为 self.view //这样 这两种操作才会出现动画, 因为我们将动画Transition 设置在父视图(容器上)了 [UIView commitAnimations];
在ios4以后的版本中
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
//这里可以设置 动画的动作 既可以改变某个视图的属性 也可以切换视图
//但是都要注意 上面 transitionWithView 的对象一定要设置正确
}
completion:^(BOOL finished){
// Save the old text and then swap the views.
}];
更简单的动画切换视图的方法
[UIView transitionFromView:self.view1 toView:self.view2 duration:3.0 options:UIViewAnimationOptionTransitionCurlUp completion^{
}];
浙公网安备 33010602011771号