这是奇怪的事情, 我通过以下代码移动UIView的位置,它在ios7中完美运行,但在ios8动画中重置动画,即使我在控制器中查找任何标签的文本,这对我来说真的很奇怪
if (!self.setTouch) {
[UIView animateWithDuration:kViewAnimateWithDuration
delay:kViewDelay
options:UIViewAnimationOptionCurveEaseInOut |
UIViewAnimationOptionAllowUserInteraction
animations:^{
//Move frame or transform view
[self.sliderView setFrame:CGRectMake(self.sliderView.frame.origin.x,-205,self.sliderView.frame.size.width,249)];
self.setTouch = YES;
// [self.containerView setFrame:CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y +171, width_b, height_b -171)];
} completion:^(BOOL finished) {
self.setTouch = YES;
}];
} else {
[UIView animateWithDuration:kViewAnimateWithDuration
delay:kViewDelay
options:UIViewAnimationOptionCurveEaseInOut |
UIViewAnimationOptionAllowUserInteraction
animations:^{
[self.sliderView setFrame:CGRectMake(self.sliderView.frame.origin.x,0.0f,self.sliderView.frame.size.width,249.0)];
self.setTouch = NO;
} completion:^(BOOL finished) {
self.setTouch = NO;
}];
}
以下是更改标签文字的代码:
NSTimer *timer= [NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:@selector(change_announcement:) userInfo:nil repeats:YES];
这是实际的方法:
(IBAction)change_announcement:(id)sender {
if ([_announcements count] == 0) {
return;
}
AnnouncementDAO *ob = [_announcements objectAtIndex:_index];
if(_isArabic){
// [_label_announcementEn setHidden:YES];
//[_label_announcementAr setHidden:NO];
[_label_announcementAr setText:ob.announcementArabicTitle];
} else{
// [_label_announcementAr setHidden:YES];
// [_label_announcementEn setHidden:NO];
[_label_announcementEn setText:ob.announcementEngTitle];
}
if (_index >= [_announcements count]-1) {
// NSLog(@"Make index 0");
_index = -1;
}
_index ++;
}
当我在NSLog sliderView约束时,我看到以下输出:
"<NSIBPrototypingLayoutConstraint:0x7b048740 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIView:0x7b04b6a0](LTR) (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b048710 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x7b04b6a0] (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b0486e0 'IB auto generated at build time for view with fixed frame' H:[UIView:0x7b04b6a0(768)]>",
"<NSIBPrototypingLayoutConstraint:0x7b0486b0 'IB auto generated at build time for view with fixed frame' V:[UIView:0x7b04b6a0(25)]>",
"<NSIBPrototypingLayoutConstraint:0x7b048680 'IB auto generated at build time for view with fixed frame' H:|-(348)-[UIButton:0x7b0e72b0](LTR) (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b048650 'IB auto generated at build time for view with fixed frame' V:|-(206)-[UIButton:0x7b0e72b0] (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b048620 'IB auto generated at build time for view with fixed frame' H:[UIButton:0x7b0e72b0(73)]>",
"<NSIBPrototypingLayoutConstraint:0x7b0485f0 'IB auto generated at build time for view with fixed frame' V:[UIButton:0x7b0e72b0(22)]>",
"<NSIBPrototypingLayoutConstraint:0x7b0485c0 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIView:0x7b04d690](LTR) (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b048590 'IB auto generated at build time for view with fixed frame' V:|-(25)-[UIView:0x7b04d690] (Names: '|':UIView:0x7b04b710 )>",
"<NSIBPrototypingLayoutConstraint:0x7b048560 'IB auto generated at build time for view with fixed frame' H:[UIView:0x7b04d690(768)]>",
"<NSIBPrototypingLayoutConstraint:0x7b048530 'IB auto generated at build time for view with fixed frame' V:[UIView:0x7b04d690(181)]>"
答案 0 :(得分:1)
首先关闭..将您的代码更改为此...
[UIView animateWithDuration:kViewAnimateWithDuration
delay:kViewDelay
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect sliderFrame = self.sliderView.frame;
if (!self.setTouch) {
//Move frame or transform view
self.sliderView.frame = CGRectMake(CGRectGetMinX(sliderFrame), -205, CGRectGetWidth(sliderFrame), 249);
self.setTouch = YES;
//[self.containerView setFrame:CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y +171, width_b, height_b -171)];
} else {
self.sliderView.frame = CGRectMake(CGRectGetMinX(sliderFrame), 0.0, CGRectGetWidth(sliderFrame), 249);
self.setTouch = NO;
}
}
completion:nil];
不需要使它变得比它需要的更复杂。
第二......你在使用AutoLayout吗?
修改强>
您正在使用AutoLayout。这就是为什么它不起作用。使用AutoLayout时,您无法直接更改视图的框架。
要为视图设置动画(或者只是移动视图),您必须更改该视图周围的约束。您无法触摸框架或中心。它只是没有用。
您需要获取要更改的约束的引用,并使用它来移动滑块视图。
我建议您查看Ray Wenderlich的网站。有一些很棒的AutoLayout教程可以用AutoLayout覆盖动画。