zoukankan      html  css  js  c++  java
  • IOS 作业项目(3) 霓虹灯效果

    先上效果图

    #import "CHViewController.h"
    @interface CHViewController ()
    {
        int i;
        int j;
    }
    @property NSInteger isStart;
    @property (nonatomic,retain) NSMutableArray *viewArray;
    @property (nonatomic,retain) UIView *neonView;
    @property (nonatomic,retain)   NSTimer *timer;

    @end

    static inline CGRect rectWithScale(CGRect rect,CGFloat scale)
    {
        rect.size.width+=scale;
        rect.size.height+=scale;
        return rect;
    }

    @implementation CHViewController
    -(UIColor *)getRandomColor:(NSInteger)max add:(NSInteger)num
    {
        CGFloat r,g,b;
        r=arc4random()%max +num;
        g=arc4random()%max +num;
        b=arc4random()%max +num;
        return [UIColor colorWithRed:r/225.0 green:g/225.0 blue:b/225.0 alpha:1.0f];
    }

    - (void)viewDidLoad
    {
        i=0;//视图下标
        j=0;
            _isStart=0;
        ///////////背景色
        UIView *backGround=[[UIView alloc]initWithFrame:self.view.bounds];
        backGround.backgroundColor= [self getRandomColor:31 add:95];
        [self.view addSubview:backGround];
        //////////标题栏视图设置
        UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];
        titleView.backgroundColor=[UIColor colorWithRed:33/255.0 green:33/255.0  blue:33/255.0  alpha:0.5];
        [backGround addSubview:titleView];
        //////////按钮设置
       UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame=CGRectMake(20, backGround.bounds.size.height-130, 280, 40);
        [button setTitle:@"Start" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.backgroundColor=[UIColor whiteColor];
        [backGround addSubview:button];
        [button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        
        ///////////////霓虹灯框视图设置
        _neonView=[[UIView alloc]initWithFrame:CGRectMake(50, 60, 220, 220)];
        _neonView.backgroundColor=[UIColor whiteColor];
        [backGround addSubview:_neonView];
     
        //////////////zoom视图入数组
        _viewArray=[[NSMutableArray alloc]init];
        for (int index=0; index<1000; index++) {
            UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,0,5,5)];
              CGPoint point=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
            view.center=point;
                view.bounds=rectWithScale(view.bounds, 4.3f);
                view.backgroundColor=[self getRandomColor:256 add:0];
            [_viewArray addObject:view];
        }
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }

    -(void)onClick:(UIButton *)button
    {
        i=0;

        if (_isStart==0) {
    _timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime:) userInfo:nil repeats:YES];
            _isStart=1;
            [button setTitle:@"Stop" forState:UIControlStateNormal];
            
        }
        else
        {
            _isStart=0;
            [button setTitle:@"Start" forState:UIControlStateNormal];
            [_timer invalidate];
        }
        }

    -(void)showTime:(NSTimer *)timer
    {
     
       for (j=0; j<i; j++) {
         if (((UIView*)_viewArray[j]).bounds.size.height>=CGRectGetHeight(_neonView.bounds)) {
            ((UIView*)_viewArray[j]).bounds=CGRectMake(0,0,5,5);
            ((UIView*)_viewArray[j]).center=CGPointMake(CGRectGetMidX(_neonView.bounds), CGRectGetMidY(_neonView.bounds));
            [((UIView*)_viewArray[j]) removeFromSuperview];
             //[_neonView addSubview:_viewArray[j]];
            
        }
            ((UIView*)_viewArray[j]).bounds=rectWithScale(((UIView*)_viewArray[j]).bounds, 5.0f);
           // ((UIView*)_viewArray[j]).backgroundColor=[self getRandomColor:256 add:0];
            if (i<1000)
           [_neonView addSubview:_viewArray[j]];
          
       }
        if (i<1000) {
             i++;
        }
        
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
      /*  UIView *view=    }*/

    }

    @end

  • 相关阅读:
    第五次作业
    第四次作业
    第三次
    request.getAttribute()和 request.getParameter()有何区别
    .Servlet API中forward()与redirect()的区别
    jsp和servlet的区别、共同点、各自应用的范围
    Servlet的生命周期
    如何从CDN加载jQuery
    window.onload()函数和jQuery中的document.ready()的区别
    jquery中$.get()提交和$.post()提交的区别
  • 原文地址:https://www.cnblogs.com/huntaiji/p/3428061.html
Copyright © 2011-2022 走看看