我的动画方法有问题
我为GoogleMap创建了自己的CalloutBubble
@interface CalloutView : UIView
@property (nonatomic) MapMarker *marker;
@end
@implementation {
UIView *titleView;
UILabel *titleLabel, *addressLabel;
}
//another init methods aren't shown
- (void)setMarker:(MapMarker *)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地图方法中返回视图
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)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这样的静态时间间隔,但动画再次立即运行,并且完成块中的标志finished
始终为YES。所以它在一秒钟内调用超过100次=(
我在iOS 7中创建应用程序。我尝试使用不同的动画选项:
UIViewAnimationOptionLayoutSubviews
UIViewAnimationOptionAllowUserInteraction
UIViewAnimationOptionBeginFromCurrentState
UIViewAnimationOptionRepeat
UIViewAnimationOptionAutoreverse
UIViewAnimationOptionOverrideInheritedDuration
UIViewAnimationOptionOverrideInheritedCurve
UIViewAnimationOptionAllowAnimatedContent
UIViewAnimationOptionShowHideTransitionViews
UIViewAnimationOptionOverrideInheritedOptions
但没有结果。
此Google地图方法有什么问题,为什么我的动画会立即运行?
PS minX,width - 我的类别。 minX set frame.origin.X。这些类别都很好。
答案 0 :(得分:1)
删除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];
}];
}