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

UIImageView, 添加动画,滑动条Slider控件,用户交互

2015-01-25 13:44 190 查看
- (void)createImageView
{
// 设置属性
self.imageView = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
20, 300,
300)];
[self.imageView
setImage:[UIImage
imageNamed:@"h2.png"]];
self.imageView.userInteractionEnabled =
YES;// 用户交互打开
[self.view
addSubview:self.imageView];
[self.imageView
release];

MyButton *button = [[MyButton
alloc]
initWithFrame:CGRectMake(0,300,
50, 30)];
[button setBackgroundColor:[UIColor
grayColor]];
[button setTitle:@"开始"
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(sliderStarAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button];
[button release];

MyButton *button2 = [[MyButton
alloc]
initWithFrame:CGRectMake(100,
300, 50,
30)];
[button2
setBackgroundColor: [UIColor
orangeColor]];
[button2
setTitle:@"结束"
forState:UIControlStateNormal];
[button2
addTarget:self
action:@selector(sliderStopAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.view
addSubview:button2];
[button2
release];
// 添加动画
self.slider = [[UISlider
alloc]initWithFrame:CGRectMake(0,
50, 200,
20)];
[_slider
addTarget:self
action:@selector(sliderAction:)
forControlEvents:UIControlEventValueChanged];

// slider.minimumValue = 10;
_slider.maximumValue =
3;
[self.view
addSubview:_slider ];
[_slider
release];
_slider.tag =
1;

NSMutableArray *arr = [NSMutableArray
array];
for (int i =
0; i <
22; i ++) {
NSString *name = [NSString
stringWithFormat:@"Zombie%d.tiff",i];
UIImage *image = [UIImage
imageNamed:name];
[arr
addObject:image];
}
self.imageView.animationImages = arr;
self.imageView.animationDuration =
1;
[self.imageView startAnimating];
// [p stopAnimating];
}
- (void)buttonAction :(id)sender
{

}
#pragma mark 滑动条slider的点击事件
- (void)sliderAction:(id)sender
{
self.imageView .animationDuration=
1 -
self.slider.value;
[self.imageView startAnimating];
}
- (void)sliderStarAction:(id)sender
{
[self.imageView startAnimating];
}
- (void)sliderStopAction:(id)sender
{
[self.imageView stopAnimating];
}
/*
动画的属性:
animationImages;
highlightedAnimationImages;
animationDuration; 动画持续的时间
animationRepeatCount; 动画重复点击次数
动画的方法:
- (void)startAnimating;
- (void)stopAnimating;
- (BOOL)isAnimating; 是否正在播放动画

*/
/*
事件的响应
事件传递:物理屏幕 -->应用程序 -->再把事件传递给window-->视图控制器-- >view
(一旦事件阻隔比如用户交互关闭,就找不到应用程序了)
问题:如果遇到按钮点击不好用没反应,首先检查用户交互

BOOL userInteractionEnabled :表示用户交互
(UILabel,UIImageview,默认是NO,UIView默认是YES)

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