zoukankan      html  css  js  c++  java
  • 实现一个view从顶部移到底部的动画 and 将RGB值转化为颜色




    @interface TimingCurveViewController : UIViewController {
      IBOutlet UIImageView *basketBall;
    }


    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

      [UIView beginAnimations:@"movement" context:nil];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; //<label id="code.timingcurve.easeIn"/>
      [UIView setAnimationDuration:1.0f];
      [UIView setAnimationRepeatCount:3];
      [UIView setAnimationRepeatAutoreverses:YES];
      CGPoint center = basketBall.center;
      if(center.y > 85.0f) {
        center.y -= 295.0f;
        basketBall.center = center;
      } else {
        center.y += 295.0f;
        basketBall.center = center;
      }
      [UIView commitAnimations];

    }




    - (void)viewDidLoad{
        [super viewDidLoad];
        self.view.backgroundColor = [self colorWithRGBHexString:@"#abcdef"];
    }


    - (UIColor *)colorWithRGBHexString:(NSString *)rgbColor{
        NSString *cString = rgbColor;
        
        //去除空格并大写NSCharacterSetwhitespaceAndNewlineCharacterSet
        
        cString = [[cString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
        
        if ([cString length] < 6) {
            
            //返回默认颜色
            
            return [UIColor redColor];
            
        }
        
        if ([cString hasPrefix:@"0x"]) {
            
            cString = [cString substringFromIndex:2];
            
        }else if ([cString hasPrefix:@"#"]){
            
            cString = [cString substringFromIndex:1];
            
        }
        
        if ([cString length] != 6) {
            
            //返回默认颜色
            
            return [UIColor redColor];
            
        }
        
        NSRange range;
        
        range.length = 2;
        
        range.location = 0;
        
        NSString *rString = [cString substringWithRange:range];
        
        range.location = 2;
        
        NSString *gString = [cString substringWithRange:range];
        
        range.location = 4;
        
        NSString *bString = [cString substringWithRange:range];
        
        
        
        unsigned int r,g,b;
        
        [[NSScanner scannerWithString:rString] scanHexInt:&r];
        
        [[NSScanner scannerWithString:gString] scanHexInt:&g];
        
        [[NSScanner scannerWithString:bString] scanHexInt:&b];
        
        
        
        return [UIColor colorWithRed:(float)r/255.0 green:(float)g/255.0 blue:(float)b/255.0 alpha:1.0f];
    }

  • 相关阅读:
    Shell基本语法
    CURL简单使用
    <C> 字符串简单习题
    <C> 字符串相关的函数
    <C> 内存分区
    <C> 最大值以及最大值下标 二分查找(折半查找)
    <C> 函数 函数指针
    <C> 冒泡排序及其非常非常非常简单的优化
    <C> typedef 宏 const 位运算
    <C> 数组
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3089632.html
Copyright © 2011-2022 走看看