【发布时间】:2013-08-23 10:42:47
【问题描述】:
我创建了一个 UISlider 用于类似“解锁滑块”的元素。我写的动画只指向一个滑块时效果很好。但我需要使用 for 循环来动态创建滑块。当我创建滑块时动画不起作用为滑块添加标签并将动画功能添加到for循环中的滑块,如下所示:
for (int i = 0; i < rowCount; i++){
...
UISlider *slider=[[UISlider alloc] initWithFrame:CGRectMake(5+ xInc, 25+yInc, 322, 40)];
//give a id tag to the slider
[slider setTag:i*10];
//set a action to the slider
[slider addTarget:self action:@selector(UnlocklinkSlider:) forControlEvents:UIControlEventTouchUpInside];
...
而动画功能是:
- (void)UnlocklinkSlider:(UISlider*)slider
{
for (int i = 0; i < rownumber; i++){
UIImageView *frontimg = (UIImageView *)[self.view viewWithTag:i*10+1];
...
if (slider.tag==i*10) {
if(slider.value >= 0.5){
// user did not slide far enough, so return back to 0 position
[UIView beginAnimations: @"SlideCanceled" context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.35];
// use CurveEaseOut to create "spring" effect
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
...
[UIView commitAnimations];
...
}
else{
...
}
}
}
}
但是动画不能以这种方式工作。有人知道为什么吗?
【问题讨论】:
-
循环的目的是什么?您要为哪些属性设置动画?在什么情况下它不起作用?
-
其实是用来创建一个滑动按钮的,如果我滑到最左边点击,它会去网页1,如果我滑到最右边点击,它会去到网页 2,如果我既不向左也不向右侧滑动,它将返回到左侧或右侧。这些按钮是指向某些网站的链接,具有两种不同的访问方式——网页 1 和网页 2,我可以通过 uitableview 将按钮添加到不同的网站。
-
好的,当然,但是您通过了滑块,为什么要循环而不是使用滑块来确定要做什么?
-
我想给滑块写一个动画让它不会那么快返回,但是滑块的动画不起作用。
-
循环是创建多个滑块,每个滑块有两个访问
标签: objective-c animation for-loop uislider