1实现原理

创建一个自定义控件,控件中显示文本,同时设置一个动画,三秒钟后,控件的alpha为0,动画完成后,控件移出掉ViewControl

2 创建PopView

2.1 PopView.h 部分

@interface PopView : UIView{    UILabel         *_textLabel;    int             _queueCount;}- (void) setText:(NSString *) text;@end

2.2 PopView.m

#import "PopView.h"#import <QuartzCore/QuartzCore.h>@implementation PopView- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0.75f];        self.layer.cornerRadius = 5.0f;        _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 10)];        _textLabel.numberOfLines = 0;        _textLabel.font = [UIFont systemFontOfSize:17];        _textLabel.textColor = [UIColor whiteColor];        _textLabel.textAlignment = NSTextAlignmentCenter;        _textLabel.backgroundColor = [UIColor clearColor];        _textLabel.textAlignment = NSTextAlignmentCenter;        [self addSubview:_textLabel];        _queueCount = 0;    }    return self;}- (void) setText:(NSString *) text{    _textLabel.frame = CGRectMake(0, 0, 100, 10);    _queueCount ++;    self.alpha = 1.0f;    _textLabel.text = text;    [_textLabel sizeToFit];    CGRect frame = CGRectMake(5, 0, _textLabel.frame.size.width, _textLabel.frame.size.height);    _textLabel.frame = frame;   frame =  CGRectMake(self.frame.origin.x, self.frame.origin.y, _textLabel.frame.size.width+10, _textLabel.frame.size.height+10);    self.frame = frame;    [UIView animateWithDuration:3.0                          delay:0.0                        options:UIViewAnimationOptionCurveEaseIn                     animations:^{                         self.alpha = 0;                     }                     completion:^(BOOL finished){                         if (_queueCount == 1) {                             [self removeFromSuperview];                         }                        _queueCount--;                     }     ];    }@end

3 调用方式:

[self.view addSubview:_popView];    [_popView setText:@"合成恢复"];

更多相关文章

  1. Android(安卓)性能优化 二 TraceView工具的使用
  2. Android属性动画之ObjectAnimator使用
  3. Android(安卓)揭露动画(Reveal Effect)的兼容实现
  4. Android使用Rotate3dAnimation实现3D旋转动画效果的实例代码
  5. android 10.0 以上隐藏方法无法调用 #Accessing hidden method
  6. Android(安卓)AsyncTask 浅析(源代码取自 API level 23)
  7. [Android] 开发资料收集:视图、组件、自定义控件
  8. android常用的API接口调用
  9. StageFright框架流程解读

随机推荐

  1. Android基础入门教程——2.3.11 Date & T
  2. android中xml直接转json
  3. 基于Eclipse平台的Android(安卓)OpenCV开
  4. 命名规范,编码规则(Android版)
  5. 聊聊Service(二)
  6. Android(安卓)EventBus使用
  7. Android(安卓)热修复对比选择
  8. Android(安卓)流量分析 tcpdump & wiresh
  9. 深入浅出学习 Android之Android布局管理:L
  10. 【 Android(安卓)10 四大组件 】系列 --