Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 - Why is CGAffine Transform working properly on iOS8 but not iOS7?

I am having a problem when using CGAffineTransformMakeTranslation on iOS7. The view I am using the CGAffineTransformMakeTranslation is going to a different position when running iOS7 and iOS8. Why is this and what am I doing wrong?

I have a view that I am calling "hud" that is the length of its parentView and 125.0 tall. I am using Auto Layout and here is a screenshot of my story board so you can see how I have the constraints set up. The container view is a collection view of photos.

Storyboard

I have the "hud" hide right away with a transform downward and when a photo is selected it will slide back up into view.

-(void)showHud:(BOOL)show
{
    NSLog(@"Frame Height: %f", hud.frame.size.height);

    if (show && !hudSelectionMode)
    {
        [UIView animateWithDuration:0.5 delay:0 options:0
                     animations:^{
                         hud.transform = CGAffineTransformMakeTranslation(0, 0);
                         hud.alpha = 0.8f;
                     }
                     completion:^(BOOL finished){
                     }
     ];

    }
    else if (!show && !hudSelectionMode)
    {

    [UIView animateWithDuration:0.5 delay:0 options:0
                     animations:^{
                         hud.transform = CGAffineTransformMakeTranslation(0, hud.frame.size.height);
                         hud.alpha = 0.8f; // will be 0.0 when not testing
                     }
                     completion:^(BOOL finished){
                     }
     ];


    }

}

Here is the problem On iOS8 this works flawlessly the hud is hidden from the start and will slide up when an image is selected: Hud HiddenHud Showing

However when running on iOS7 devices the hud is not where I would expect it to be: Hud ios7 "hidden"Hud ios7 showing

If I comment out all the code in -(void)showHud:(BOOL)show the hud will sit at the bottom of the parentView where I would expect it to on both 7 and 8.

like image 917
Ahufford Avatar asked Oct 07 '14 20:10

Ahufford


1 Answers

On iOS7 you need to multiply the translation value by the scaleFactor of the device. On iOS8 this seems to be done automatically, but not on iOS7.

like image 86
Jordi Avatar answered Oct 15 '22 04:10

Jordi