2

I have trouble with method for animation

I've created my own CalloutBubble for GoogleMap

@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

In my viewController I create property

@implementation MapVC {
    CalloutView *calloutView;
}

And then if I try create calloutView in any method all work fine with animation, but if I return view in Google map method

- (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;
}

My animation run immediately in calloutView, and completion called immediately too, and call runningLabel method again, So it is not work like it have to. All frame is good, and timInterval always more than 4 second. I tried to write static timeinterval like 10.0, but animation again run immediately, and flag finished in completion block always YES. So it called more than 100 times in one second =(

I create app in iOS 7. I tried to use different options for animation:

UIViewAnimationOptionLayoutSubviews           
UIViewAnimationOptionAllowUserInteraction     
UIViewAnimationOptionBeginFromCurrentState    
UIViewAnimationOptionRepeat                   
UIViewAnimationOptionAutoreverse              
UIViewAnimationOptionOverrideInheritedDuration 
UIViewAnimationOptionOverrideInheritedCurve   
UIViewAnimationOptionAllowAnimatedContent     
UIViewAnimationOptionShowHideTransitionViews 
UIViewAnimationOptionOverrideInheritedOptions  

but there are no results.

What wrong in this Google map method, why my animation run immediately?

PS minX, width - my categories. minX set frame.origin.X . There are all good with this categories.

Rashad
  • 11,057
  • 4
  • 45
  • 73
user3095583
  • 75
  • 1
  • 7
  • Add NSLog("%f",timeInterval) after CGFloat timeInterval = titleLabel.width / 70;. see the output. – Rashad Feb 18 '14 at 07:30
  • @Rashad, did you read my post? I wrote that timeInterval ALWAYS more than 4 second, and I tried to use static seconds, for eample 10.0, but there are no results – user3095583 Feb 18 '14 at 07:40

1 Answers1

1

Remove UIViewAnimationOptionRepeat option Or comment the completion Block minX setting:

- (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];
        }];
}
simalone
  • 2,768
  • 1
  • 15
  • 20