ios 自定义加载动画的实现,类…

本文介绍了一个简单的iOS应用中视图旋转动画的实现过程。通过Objective-C代码创建了一个带有旋转动画按钮的应用界面,并详细展示了如何使用UIView动画方法来实现图片视图的连续旋转效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//
//  ViewController.m
//  test1222
//
//  Created by zhangjian on 16/12/22.
//  Copyright © 2016年 zhangjian. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()


{
    BOOL animating;
    UIView *bgView;
    UIView *bg1;
    UIImageView *bgImageView1;
    UIImageView *bgImageView2;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    bgView = [[UIView alloc]initWithFrame:CGRectMake((320-255)/2, 200, 255, 126)];
    [self.view addSubview:bgView];
    
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:bgView.frame];
    bgImageView.image = [UIImage imageNamed:@"d.png"];
    [self.view addSubview:bgImageView];
    
    bg1 = [[UIView alloc]initWithFrame:CGRectMake(20, (126-61)/2, 61, 61)];
    [bgImageView addSubview:bg1];
    
    bgImageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(20, (126-61)/2, 61, 61)];
    bgImageView1.image = [UIImage imageNamed:@"c1.png"];
    [bgImageView addSubview:bgImageView1];
    
    bgImageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(20, (126-61)/2, 61, 61)];
    bgImageView2.image = [UIImage imageNamed:@"c.png"];
    [bgImageView addSubview:bgImageView2];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(bgView.frame.origin.x + 61 , bg1.frame.size.height / 2 + 20, 100, 20)];
    label.text = @"加载中...";
    [bgImageView addSubview:label];
 
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(200, 100, 60, 30)];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"开始" forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(startRotate) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(50, 100, 60, 30)];
    button1.backgroundColor = [UIColor redColor];
    [self.view addSubview:button1];
    [button1 setTitle:@"停止" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(stopRotate) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void) rotateWithOptions: (UIViewAnimationOptions) options {

    [UIView animateWithDuration: 0.125f
                          delay: 0.0f
                        options: options
                     animations: ^{
                         bgImageView2.transform = CGAffineTransformRotate(bgImageView2.transform, M_PI / 2);
                     }
                     completion: ^(BOOL finished) {
                         if (finished) {
                             if (animating) {
                               
                                 [self rotateWithOptions: UIViewAnimationOptionCurveLinear];
                             } else if (options != UIViewAnimationOptionCurveEaseOut) {
                             
                                 [self rotateWithOptions: UIViewAnimationOptionCurveEaseOut];
                             }
                         }
                     }];
}

- (void) startRotate {
    if (!animating) {
        animating = YES;
        [self rotateWithOptions: UIViewAnimationOptionCurveEaseIn];
    }
}

- (void) stopRotate{

    animating = NO;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值