博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS UI 04 轨道和动画
阅读量:5959 次
发布时间:2019-06-19

本文共 4892 字,大约阅读时间需要 16 分钟。

//

//  Rootview.m

//  UI - 05 UIcontroller

//

//  Created by dllo on 15/11/12.

//  Copyright (c) 2015 dllo. All rights reserved.

//

#import "Rootview.h"

@interface  Rootview()

@property (nonatomic, retain) UIImageView *imagev;

@end

@implementation Rootview

- (instancetype)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        [self createView];

    }

    return self;

}

- (void) createView

{

    self.backgroundColor = [UIColor lightGrayColor];

    

    UISlider *sileder = [[UISlider alloc]initWithFrame:CGRectMake(50, 500, 200, 50)];

    //注意UIControlEventValueChanged 改变值的时候触发

    [sileder addTarget:self action:@selector(sliderAct:) forControlEvents:UIControlEventValueChanged];

    //当前值设定 (园钮位置改变);

    sileder.value = 0.5;

    

    //改变最大值,最小值

    sileder.maximumValue = 30;

    // sileder.minimumValue = 0;

    

    //轨迹左边颜色

    sileder.minimumTrackTintColor = [UIColor blueColor];

    //轨迹右边颜色

    sileder.maximumTrackTintColor = [UIColor orangeColor];

    sileder.thumbTintColor = [UIColor greenColor];

    

    [self addSubview:sileder];

    [sileder release];

    

    

    

    NSMutableArray *imageArr = [NSMutableArray array];

    self.imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];

  for (NSInteger i = 1; i < 17; i++) {

        

//        拼接图片的名字

//        注意!!!查看图片的序号是1还是01/001   %02ld,  2  前一位如果空了自动补零

//        若序号是001的形式 %03ld

      

        NSString *fileName = [NSString stringWithFormat:@"happy_%04ld.png", i];

      //  创建uiimage类型的对象

        UIImage *image = [UIImage imageNamed:fileName];

        

         [imageArr addObject:image];

    }

    for (NSInteger i = 1 ; i < 26; i++) {

        NSString *c  = [NSString stringWithFormat:@"heart_BG_%04ld.png", i];

        UIImage *image = [UIImage imageNamed:c];

        [imageArr addObject:image];

    }

//    for (NSInteger i = 1 ; i < 5; i++) {

//        NSString *c  = [NSString stringWithFormat:@"heart_broken_%04ld.png", i];

//        UIImage *image = [UIImage imageNamed:c];

//        [imageArr addObject:image];

//    }

    for (NSInteger i = 1 ; i < 16; i++) {

        NSString *c  = [NSString stringWithFormat:@"heart_jump_%04ld.png", i];

        UIImage *image = [UIImage imageNamed:c];

        [imageArr addObject:image];

    }

    for (NSInteger i = 1 ; i < 29; i++) {

        NSString *c  = [NSString stringWithFormat:@"hold_hand_%04ld.png", i];

        UIImage *image = [UIImage imageNamed:c];

        [imageArr addObject:image];

    }

    for (NSInteger i = 33 ; i < 47; i++) {

        NSString *c  = [NSString stringWithFormat:@"hold_heart_%04ld.png", i];

        UIImage *image = [UIImage imageNamed:c];

        [imageArr addObject:image];

    }

    for (NSInteger i = 1 ; i < 25; i++) {

        NSString *c  = [NSString stringWithFormat:@"hold_heart_B_%02ld.png", i];

        UIImage *image = [UIImage imageNamed:c];

        [imageArr addObject:image];

    }

    

   // 要播放的图片数组

    self.imagev.animationImages = imageArr;

    

    self.imagev.image = [UIImage imageNamed:@"happy_0001.png"];

    [self addSubview:self.imagev];

    

    // 播放时间

   self.imagev.animationDuration = sileder.maximumValue - sileder.value ;

   // 重复次数 - 默认是0 即无线循环

  // self.imagev.animationRepeatCount = 2;

    

    

    

    

   //  播放动画

    [self.imagev startAnimating];

    

   //  停止播放

   // [imagev stopAnimating];

    

    

   

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(50, 300, 100, 30);

    button.backgroundColor = [UIColor redColor];

      [button setTitle:@"结束" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(stop:) forControlEvents:   UIControlEventTouchUpInside];

    [self addSubview:button];

    

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];

    button1.frame = CGRectMake(180, 300, 100, 30);

    button1.backgroundColor = [UIColor orangeColor];

    [button1 setTitle:@"开始" forState:UIControlStateNormal];

    [button1 addTarget:self action:@selector(start:) forControlEvents:   UIControlEventTouchUpInside];

    [self addSubview:button1];

    

    

    UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"王宁", @"杨忠祥", @"初旭", nil]];

    segmentC.frame = CGRectMake(10, 400, 300, 30);

    

    //边框颜色

    segmentC.tintColor =  [UIColor redColor];

    

    //背景颜色

    segmentC.backgroundColor = [UIColor blackColor];

    

    

    //设置选择状态  选择第几个背景变蓝

    segmentC.selectedSegmentIndex = 0;

    

    //插入

    [segmentC insertSegmentWithTitle:@"" atIndex:1 animated:NO];

    

    

    //修改

    [segmentC setTitle:@"由盛焱" forSegmentAtIndex:0];

    

    //插入带图片的segment

    UIImage *image = [UIImage imageNamed:@"1.png"];

    

    //图片渲染

    image  = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    [segmentC insertSegmentWithImage:image atIndex:2 animated:YES];

    

    [segmentC addTarget:self action:@selector(seAction:) forControlEvents: UIControlEventValueChanged  ];

    [self addSubview:segmentC];

    [segmentC release];

}

- (void)seAction:(UISegmentedControl *)sender

{

    NSLog(@" %ld", sender.selectedSegmentIndex);

}

- (void)start:(UIButton *)sender

{

    [self.imagev startAnimating];

}

- (void)stop:(UIButton *)sender

{

    [self.imagev stopAnimating];

}

- (void)sliderAct: (UISlider *)sender {

    

    //也可以用tag 来实现    uiimageview *a = (uiimageview *)[self viewWIthtag : ]

    self.imagev.animationDuration =  sender.maximumValue - sender.value + 0.01;

    [self.imagev startAnimating];

    

    

    

    

//    NSLog( @"当前滚动条的值为:%f", sender.value);

    

}

@end

转载于:https://www.cnblogs.com/yuhaojishuboke/p/5043086.html

你可能感兴趣的文章
faster-RCNN台标检测
查看>>
Unix环境高级编程 centos中配置apue编译环境
查看>>
运算符
查看>>
数据结构之各排序算法
查看>>
网页分帧操作<frameset>,<iframe>标签
查看>>
Vue生产环境部署
查看>>
酒店之王
查看>>
html5判断用户摇晃了手机(转)
查看>>
VS下Qt4.8.4安装
查看>>
Linux df命令
查看>>
redhat6.5 配置使用centos的yum源
查看>>
取得内表的数据数
查看>>
在一个程序中调用另一个程序并且传输数据到选择屏幕执行这个程序
查看>>
“=” “:=” 区别
查看>>
pwnable.kr lotto之write up
查看>>
python之UnittTest模块
查看>>
HDOJ_ACM_Rescue
查看>>
笔记纪录
查看>>
九、oracle 事务
查看>>
Git - 操作指南
查看>>