Search code examples
animationios6uitextviewios7

Bubble Speech Animation works fine in iOS6 but not in iOS7


I have an array of dictionaries, each dictionary has some text, a CGRect an a delay. I setup a UITextView with a background and then runt through the array starting the next animation after the previews is finished. All works fine on iOS6 but on iOS7 if flickers during the animation and then vanishes during the delay for the disappear.

I call this in the viewDidAppear

-(void)speachInit
{
    // Make an image with the background of the bubble, use CapInsets to preserve the edges of the image
    UIImage *bubble = [[UIImage imageNamed:@"bubble_bottom.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 12, 12)];

    // Add the image to an image view
    UIImageView *bubbleImage = [[UIImageView alloc] initWithImage:bubble];
    bubbleImage.frame = CGRectZero;
    [bubbleImage setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

    // Setup a text View with whatever is needed
    UITextView *bubbletext = [[UITextView alloc]initWithFrame:CGRectZero];
    bubbletext.textColor = [UIColor lightGrayColor];
    bubbletext.backgroundColor = [UIColor clearColor];
    bubbletext.font = [UIFont fontWithName:@"Helvetica Neue" size:13];
    [bubbletext setEditable:NO];
    [bubbletext setTextAlignment:NSTextAlignmentJustified];

    [bubbletext setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

    // Add the image to the textView and then push to back
    [bubbletext addSubview:bubbleImage];
    [bubbletext sendSubviewToBack:bubbleImage];

    // Add the text (including the image) to the main view
    [self.view addSubview:bubbletext];

    // Start the animation
    [self speachStart:bubbletext];
}

Then at the bottom of this I start this animation

-(void)speachStart:(UITextView *)speachView
{
    // Test we have reached the end of the array
    if([speaches count] > speachCount)
    {
        // Start an animation from 0,0 to the place specified in the array
        [UIView animateWithDuration:0.3
                          delay:0.3
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^(void)
            {
                speachView.text = [speaches objectAtIndex:speachCount][@"speachText"];
                speachView.frame = [[speaches objectAtIndex:speachCount][@"speachShape"]CGRectValue];

            } completion:^(BOOL finished)
            {
                // Once completed add new animation to reduce to 0,0
                [UIView animateWithDuration:0.3
                               delay:[[speaches objectAtIndex:speachCount][@"speachDuration"]floatValue]
                             options:UIViewAnimationOptionCurveEaseIn
                          animations:^(void)
                    {
                        speachView.frame = CGRectZero;
                    } completion:^(BOOL finished)
                    {
                        // Once this has completed increment the array pointer
                        speachCount++;
                        // And start over with next item in array
                        [self speachStart:speachView];
                    }];
            }];
    }
} 

Solution

  • In the end I removed the Frame changes in the animation and used Alpha changes which still looks good.

    So for example the first part started like this and then the completion animation just went back to Alpha 0.

        speachView.alpha = 0.0f;
        speachView.text = [speaches objectAtIndex:speachCount][@"speachText"];
        speachView.frame = [[speaches objectAtIndex:speachCount][@"speachShape"]CGRectValue];
    
        [UIView animateWithDuration:0.3
                              delay:0.3
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^(void)
                {
    //                    speachView.text = [speaches objectAtIndex:speachCount][@"speachText"];
    //                    speachView.frame = [[speaches objectAtIndex:speachCount][@"speachShape"]CGRectValue];
                    speachView.alpha = 1.0f;
                } completion:^(BOOL finished)
                {........ and so on