动画方法有问题
我已经为 GoogleMap 创建了自己的 CalloutBubble
@interface CalloutView : UIView
@property (nonatomic) MapMarker *marker;
@end
@implementation {
UIView *titleView;
UILabel *titleLabel, *addressLabel;
}
//another init methods aren't shown
- (void)setMarkerMapMarker *)marker
{
_marker = marker;
titleLabel.text = marker.university.name;
addressLabel.text = marker.university.address;
[titleLabel sizeToFit];
titleLabel.minX = 0;
[titleLabel.layer removeAllAnimations];
if (titleLabel.width > titleView.width)
[self runningLabel];
}
- (void)runningLabel
{
CGFloat timeInterval = titleLabel.width / 70;
[UIView animateWithDuration:timeInterval delay:1.0 options:UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionRepeat animations:^{
titleLabel.minX = -titleLabel.width;
} completion:^(BOOL finished) {
titleLabel.minX = titleView.width;
[self runningLabel];
}];
}
@end
在我的 viewController 我创建属性
@implementation MapVC {
CalloutView *calloutView;
}
然后,如果我尝试在任何方法中创建 calloutView,所有动画都可以正常工作,但如果我在 Google map 方法中返回 View
- (UIView *)mapViewGMSMapView *)mapView markerInfoWindowGMSMarker *)marker
{
if (!calloutView)
calloutView = [[CalloutView alloc] initWithFrame:CGRectMake(0, 0, 265, 45.5)];
calloutView.marker = (MapMarker *)marker;
return calloutView;
}
我的动画在 calloutView 中立即运行,完成也立即调用,并再次调用 runningLabel 方法,所以它不是必须的。所有帧都很好,并且 timInterval 总是超过 4 秒。我尝试编写像 10.0 这样的静态时间间隔,但动画再次立即运行,并且在完成 block 中标记 finished 始终是。所以它在一秒钟内调用了100多次=(
我在 iOS 7 中创建应用程序。我尝试使用不同的动画选项:
UIViewAnimationOptionLayoutSubviews
UIViewAnimationOptionAllowUserInteraction
UIViewAnimationOptionBeginFromCurrentState
UIViewAnimationOptionRepeat
UIViewAnimationOptionAutoreverse
UIViewAnimationOptionOverrideInheritedDuration
UIViewAnimationOptionOverrideInheritedCurve
UIViewAnimationOptionAllowAnimatedContent
UIViewAnimationOptionShowHideTransitionViews
UIViewAnimationOptionOverrideInheritedOptions
但没有结果。
这个谷歌地图方法有什么问题,为什么我的动画立即运行?
PS minX,宽度 - 我的类别。 minX 设置 frame.origin.X 。这个类别都有不错的。
Best Answer-推荐答案 strong>
移除 UIViewAnimationOptionRepeat 选项或注释完成 Block minX 设置:
- (void)runningLabel
{
CGFloat timeInterval = titleLabel.width / 70;
[UIView animateWithDuration:timeInterval delay:1.0 options:UIViewAnimationOptionOverrideInheritedDuration | UIViewAnimationOptionRepeat animations:^{
titleLabel.minX = -titleLabel.width;
} completion:^(BOOL finished) {
//titleLabel.minX = titleView.width; //this is the problem, you should not set minX again while UIViewAnimationOptionRepeat also is animation option
[self runningLabel];
}];
}
关于ios 7 UIView animateWithDuration : .。立即运行,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/21846898/
|