2012-08-10 55 views
2

我有一个UILabel可以滑入或滑出视图,但滑入其中后会消失。我希望它坚持下去。UILabel在animateWithDuration后消失

我该如何做到这一点?另外,为什么会发生这种情况?

下面的代码:

[UIView animateWithDuration:0.1 
          delay:0.0 
         options:UIViewAnimationOptionAutoreverse 
        animations:^{ 
         [self.listLabel setFrame:CGRectMake(325, 141, 320, 181)]; 
        } 
        completion:nil]; 

感谢。

回答

2

official documentation

UIViewAnimationOptionAutoreverse 向后和向前运行的动画。必须与UIViewAnimationOptionRepeat选项结合使用。

0

为什么不使用UIViewAnimationOptionCurveEaseOut和UIViewAnimationOptionCurveEaseIn动画选项作为标签? 只需设置标签的frame.origin.x = [在超级视角范围的右侧外] ,并在想要再次使用EasyOut动画进行滑动时将其设置回原始位置。 这就是我讲的东西......

CFRect frame = self.listLabel.frame; 
//Point to hide your label by sliding it outside the right side of it's parent's view. 
// mask or clipToBounds of parent's view must be YES 
frame.origin.x = [self.listLabel.superview.frame.size.width]; 
[UIView animateWithDuration:0.1 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseIn 
       animations:^{ 
        [self.listLabel setFrame:frame]; 
       } 
       completion:nil]; 

,当你想在向后滑动,使用相反的动画和标签的原始位置,当然你需要保存它的原始位置的地方,所以你可以滑动 - 在它回来。

[UIView animateWithDuration:0.1 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        [self.listLabel setFrame:label_original_frame]; 
       } 
       completion:nil]; 
0

UIViewAnimationOptionAutoreverse是为循环动画设计的。只是反弹的东西离屏幕和背部,你应该只把它写成2级的动画:

CGRect originalFrame = self.listLabel.frame; 
[UIView animateWithDuration:0.05 
         delay:0.0 
        options:UIViewAnimationOptionLayoutSubviews 
       animations:^{ 
        [self.listLabel setFrame:CGRectMake(325, 141, 320, 181)]; 
       } 
       completion:^(BOOL finished){ 
        [UIView animateWithDuration:0.05 
              delay:0.0 
             options:UIViewAnimationOptionLayoutSubviews 
            animations:^{ 
             [self.listLabel setFrame:originalFrame]; 
            } 
            completion:nil]; 
       } 
]; 
0

由于仍有似乎没有有效的答案,我提出了一个(现在可以)做法:

在Xcode中6 ,应用程序在模拟器中运行,转到顶部栏的“Debug”,选择“View Debugging”和“Capture View Hierarchy”。然后去搜索你丢失的标签。您还可以在右侧的Xcode栏中看到Label的属性等。