你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS 動畫

IOS 動畫

編輯:IOS開發綜合

//uiview動畫
    //開始動畫
    [UIView beginAnimations:nil context:nil];
    
    //運動的時間
    [UIView setAnimationDuration:2.f];
    //延時啟動
    [UIView setAnimationDelay:2];
    //速度曲線(可以改變速度)
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    //代理
    [UIView setAnimationDelegate:self];
    //代理方法 開始時候執行
    [UIView setAnimationWillStartSelector:@selector(start)];
    //結束時候執行
    [UIView setAnimationDidStopSelector:@selector(stop)];
    //重復執行
    [UIView setAnimationRepeatAutoreverses:YES];
    //重復幾次
    [UIView setAnimationRepeatCount:2];
    //重復
    [UIView setAnimationsEnabled:YES];
    //翻轉
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.Testview cache:YES];
    
    //動畫過程
    self.Testview.backgroundColor = [UIColor colorWithRed:arc4random()%255/256.0 green:arc4random()%255/256.0 blue:arc4random()%255/256.0 alpha:1];
    //提交動畫
    [UIView commitAnimations];

//系統自帶block

    [UIView animateWithDuration:2.f animations:^{

        

    }];

[UIView transitionWithView:self.view duration:2.f options:(UIViewAnimationOptionTransitionFlipFromTop) animations:^{
        NSLog(@"開始動畫");
        self.MyView.backgroundColor = [UIColor greenColor];
    } completion:^(BOOL finished) {
        self.MyView.backgroundColor = [UIColor orangeColor];
        NSLog(@"動畫結束");
    }];

[UIView animateWithDuration:2.f animations:^{
//        self.MyView.transform = CGAffineTransformTranslate(self.MyView.transform, 0.5f, 0.5f);
        self.MyView.transform = CGAffineTransformRotate(self.MyView.transform, M_PI_2);
        
    }];
//模擬自帶block自己寫的方法
-(void)myAnimationDuration:(NSTimeInterval)time
                 animation:(myBlock)ani
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:time];
    ani();
    [UIView commitAnimations];
}

//給view設置邊緣 描邊粗細
    self.myview.layer.borderWidth = 20;
    //描邊顏色(注意類型轉換)
    self.myview.layer.borderColor = [UIColor yellowColor].CGColor;
    //陰影偏移
    self.myview.layer.shadowOffset = CGSizeMake(50, 50);
    //陰影顏色
    self.myview.layer.shadowColor = [UIColor grayColor].CGColor;
    //陰影透明度
    self.myview.layer.shadowOpacity = 0.8;
    //模糊程度
    self.myview.layer.shadowRadius = 10

//第一種


CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.duration = 2.0;
    animation.repeatCount = 30;
    animation.autoreverses = YES;
    
    NSArray *array = @[[NSValue valueWithCGPoint:CGPointMake(25, 25)],[NSValue valueWithCGPoint:CGPointMake(200, 25)],[NSValue valueWithCGPoint:CGPointMake(25, 200)],[NSValue valueWithCGPoint:CGPointMake(200, 200)]];
    
    animation.values = array;
    [self.myview.layer addAnimation:animation forKey:@"asd"];

//第二種

CAAnimationGroup *group = [CAAnimationGroup animation];
    //1
    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    //初始值
    animation1.fromValue = [NSNumber numberWithFloat:0.3];
    //結束值
    animation1.toValue = [NSNumber numberWithFloat:3.0];
    //2
    CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation2.values = @[[NSValue valueWithCGPoint:CGPointMake(25, 25)],[NSValue valueWithCGPoint:CGPointMake(200, 25)],[NSValue valueWithCGPoint:CGPointMake(25, 200)],[NSValue valueWithCGPoint:CGPointMake(200, 200)]];
    //3
    group.duration = 2.0;
    group.autoreverses = YES;
    group.repeatCount = 3;
    group.animations = @[animation1,animation2];

    
    [self.myview.layer addAnimation:group forKey:@"asd"];

//第三種

CATransition *ani = [CATransition animation];
    /*
     pageCurl            向上翻一頁
     pageUnCurl          向下翻一頁
     rippleEffect        滴水效果
     suckEffect          收縮效果,如一塊布被抽走
     cube                立方體效果
     oglFlip             上下翻轉效果
     */
    ani.type = @"cube";
    ani.repeatCount = 200;
    ani.duration = 1;
    //方向
    ani.subtype = kCATransitionFromLeft;
    [self.myview.layer addAnimation:ani forKey:@"an"];









  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved