zoukankan      html  css  js  c++  java
  • 简单的实现弹幕效果

    用键盘输入,按下回车键

    #import "ViewController.h"
    
    @interface ViewController ()<UITextFieldDelegate>
    
    @property (weak, nonatomic) IBOutlet UITextField *textInPut;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        //设置文本框的代理
        self.textInPut.delegate = self;
    
    }
    
    //点击return键调用的方法
    -(BOOL)textFieldShouldReturn:(UITextField *)textField {
        
        UILabel *textLabel = [[UILabel alloc]init];
        [self.view addSubview:textLabel];
        
        textLabel.text = self.textInPut.text;
        
        //清空输入框
        self.textInPut.text = nil;
        
        //设置label的大小
        [textLabel sizeToFit];
        
        CGFloat w = textLabel.bounds.size.width;
        CGFloat h = textLabel.bounds.size.height;
        CGFloat x = [UIScreen mainScreen].bounds.size.width;
        CGFloat y = arc4random_uniform([UIScreen mainScreen].bounds.size.height -h);
        
        textLabel.frame = CGRectMake(x, y, w, h);
        
        //动画
        [UIView animateWithDuration:5.0 animations:^{
            textLabel.frame = CGRectMake(-w, y, w, h);
        }];
        
        return YES;
    }
    
    @end
  • 相关阅读:
    docker 部署 禅道系统
    docker 部署 jenkins
    运筹方法
    软件工程基础知识
    操作系统知识
    程序设计语言基础知识
    计算机组成与配置
    oracle触发器
    性能测试监控工具的使用
    数据库设计范式
  • 原文地址:https://www.cnblogs.com/ritian/p/5505357.html
Copyright © 2011-2022 走看看