博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
渐隐渐现效果代码
阅读量:4109 次
发布时间:2019-05-25

本文共 3179 字,大约阅读时间需要 10 分钟。

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

{

// only respond to mouse down events

UITouch *touch = [touches anyObject];

if ([touchphase] !=UITouchPhaseBegan)return;

isVisible = !isVisible;

// perform the fade out or fade in

CGContextRef context =UIGraphicsGetCurrentContext();

[UIView beginAnimations:nilcontext:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:1.0];

[[selfviewWithTag:IMAGE_VIEW_TAG]setAlpha:(float)isVisible];

[UIView commitAnimations];

}

转别人的

1、最简单,最实用,最常用的[移动动画]
//移动一个view
---------------------------------------------------------------------------------------------------------------------------------
+(void)MoveView:(UIView *)view To:(CGRect)frame During:(float)time{
// 动画开始
[UIView beginAnimations:nil context:nil];
// 动画时间曲线 EaseInOut效果
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
// 动画时间
[UIView setAnimationDuration:time];
view.frame = frame;
// 动画结束(或者用提交也不错)
[UIView commitAnimations];
}
---------------------------------------------------------------------------------------------------------------------------------
适用范围:
常常出现在ipad项目中,当用户点击一个图片,或者一条资讯,你将弹出一个详细页面[detailview],将起始frame初始化为 cgrectmake(self.view.frame.size.width/2,self.view.size.height/2, 0, 0),结束位置[frame] ,常用的动画间隔时间0.4f-0.6f。
[AnimtionTool MoveView:detailview To:frame During:0.5f];
效果,页面中间将从小到大显示一个view[detailview]
2、渐渐显示一个view,需要在调用此方法的类中重写此方法
---------------------------------------------------------------------------------------------------------------------------------
/*
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
      if ([animationID isEqualToString: SHOW_VIEW]) {
         //do something
      }  else if ([animationID isEqualToString:HIDDEN_VIEW]) {
         //do something
      }
}
*/
+(void)ShowView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate;{
[UIView beginAnimations:SHOW_VIEW context:nil];
[UIView setAnimationDuration:time];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:delegate];
}
view.hidden = NO;
view.layer.opacity = 1.0;
view.frame = frame;
[UIView commitAnimations];
}
---------------------------------------------------------------------------------------------------------------------------------
3、渐渐隐藏一个view
---------------------------------------------------------------------------------------------------------------------------------
+(void)HiddenView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate{
[UIView beginAnimations:HIDDEN_VIEW context:nil];
[UIView setAnimationDuration:time];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:delegate];
}
view.frame = frame;
view.layer.opacity = 0.0;
[UIView commitAnimations];
}

转载地址:http://cjosi.baihongyu.com/

你可能感兴趣的文章
牛客网编程OJ的典型输入Java模板
查看>>
Leetcode上动态规划系列经典题的Java详解
查看>>
布隆过滤器的介绍
查看>>
Letcode双指针题的Java实现(盛水容器和合并区间)
查看>>
关于比较器Comparable和Comparator
查看>>
BODAS安装的安装与配置
查看>>
BODAS说明书的中文版与相关资料总结
查看>>
关于测控系统的CAN通讯协议总结
查看>>
从SpringMVC源码分析原理
查看>>
《Java编程思想第四版》中在算法题中常用的概念总结(持续更新)
查看>>
git常用工具的原理介绍以及项目使用中常见问题(持续更新)
查看>>
Java性能监控工具Arthas实践
查看>>
Java虚拟机(JVM)调优和Debug的常用参数详解
查看>>
Java内存溢出的典型场景测试
查看>>
操作系统之进程调度与内存管理
查看>>
分布式系统中的消息队列传递
查看>>
maven如何解决依赖冲突?示例三种bug的解决
查看>>
git的回滚操作
查看>>
记一次新建操作(insert)的优化过程
查看>>
摆桶问题
查看>>