您的位置:首页 > 产品设计 > UI/UE

UI05_Control

2015-08-06 08:52 423 查看
//
//  MainViewController.m
//  UI05_Control
//
//  Created by dllo on 15/8/4.
//  Copyright (c) 2015年 Clare. All rights reserved.
//

#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface MainViewController ()
@property(nonatomic, retain)UIStepper *stepper;
@property(nonatomic, retain)AVAudioPlayer *play;

@property(nonatomic, retain)UIImageView *tomcatImageView;
@property(nonatomic, retain)NSMutableArray *picArr;

// 滑块的视图
@property(nonatomic, retain)UISlider *slider;
@end

@implementation MainViewController
- (void)dealloc
{
[_stepper release];
[_play release];
[_tomcatImageView release];
[_picArr release];
[_slider release];
[super dealloc];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

//    self.stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//    [self.view addSubview:self.stepper];
//    [_stepper release];
//
//    self.stepper.stepValue = 2;
//
//    [self.stepper addTarget:self action:@selector(stepAction:) forControlEvents:UIControlEventValueChanged];
//
//
//    // 添加音乐
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"亡灵序曲" ofType:@"mp3"];
//    self.play = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
//
//    [self.play play];
//    [_play release];
//
//    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"j.jpg"]];
//    imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//    [self.view addSubview:imageView];
//    [imageView release];
//
//    /// 毛玻璃
//    // 先创建一个毛玻璃效果
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//    // 创建一个毛玻璃视图,指定效果
//    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
//    effectView.frame = imageView.frame;
//    [imageView addSubview:effectView];
//

/// 播放gif图
self.tomcatImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview: self.tomcatImageView];
[_tomcatImageView release];

// 容器使用之前,一定要对容器进行初始化
self.picArr = [NSMutableArray array];

for (NSInteger i = 1; i < 16 ; i++) {
// 拼接图片的名称
// NSLog(@"%02ld", i);  // 两位不够用0补
NSString *picName = [NSString stringWithFormat:@"dodo_%02ld.jpg", i];
// NSLog(@"%@", picName);

/// 根据图片名找到对应的图片
UIImage *image = [UIImage imageNamed:picName];
// 把图片添加到数组中
[self.picArr addObject:image];
}

//
self.tomcatImageView.animationImages = self.picArr;

// 动画播放的时间
self.tomcatImageView.animationDuration = 5;
// 动画重复的次数
// self.tomcatImageView.animationRepeatCount = 3;

[self.tomcatImageView startAnimating];

self.slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 600, 100, 40)];
[self.view addSubview:self.slider];
[_slider release];

// 最大值,最小值
self.slider.minimumValue = 0.1;
self.slider.maximumValue = 5;
// self.slider.value =

[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

NSArray * segmentArray = [[NSArray alloc]initWithObjects:@"1", @"2", @"3",@"4", nil ];
UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:segmentArray];
segmented.frame = CGRectMake(150, 400, 100, 30);
segmented.selectedSegmentIndex = 1;
segmented.tintColor = [UIColor lightGrayColor];
[self.view addSubview:segmented];
[segmented release];

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"1", @"2", @"3", @"4"]];
seg.frame = CGRectMake(150, 450, 100, 30);
seg.selectedSegmentIndex = 1;
seg.tintColor = [UIColor lightGrayColor];
[self.view addSubview:seg];
[seg release];

}

- (void)stepAction:(UIStepper *)stepper
{
NSLog(@"%g", stepper.value);

///调整音乐音量
self.play.volume = self.stepper.value;
}

- (void)sliderAction:(UISlider *)slider
{
NSLog(@"%g", slider.value);
// 播放的时长,被slider控制
self.tomcatImageView.animationDuration = slider.value;
[self.tomcatImageView startAnimating];
}

- (void)segAction:(UISegmentedControl *)seg
{
// 按钮默认从0开始
NSLog(@"%ld", seg.selectedSegmentIndex);
}

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

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: