Giter VIP home page Giter VIP logo

fb8708184's Introduction

FB8708184

iOS 14 GM Bug - Feedback Assistant FB8708184

Purpose

This is a sample code project that replicates a bug in iOS 14 GM when the MKAnnotationView's image is set while the view is still on screen. Run "iOS14MapBug" & press the "Cycle Pin Status" button to cycle the MKAnnotationView's image.

Expected Behavior

As seen on iOS 13

iOS 13 map view not showing glitched display on annotation view image update

Actual Behavior

As seen on iOS 14 GM

iOS 14 map view showing glitched display on annotation view image update

Workaround

The issue in iOS 14 GM appears to be in the animation of the CALayer that is backing the image. A switch has been provided in the codebase to show a workaround that involves disabling animations while setting MKAnnotationView's image & then adding back an animation that duplicates what the MapKit framework was attempting to add.

If you have a MKAnnotationView subclass, you can workaround the issue like this:

- (void)setImage:(UIImage *)image {
    // Feedback Assistant ticket: FB8708184
    //
    // With iOS 14, setting the MKAnnotationView's image leads to a glitched CABasicAnimation when using images of the same size
    // from an asset catalog.
    //
    // To work around this, we create our own version of the system animation that isn't glitched, prevent
    // the system from adding the glitched system provided one, & then add our animation once the image sets are done.
    if (@available(iOS 14, *)) {
        CALayer *imageLayer = self.layer.sublayers.firstObject;

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];
        animation.fromValue = imageLayer.contents;
        animation.toValue = (__bridge id)image.CGImage;
        animation.fillMode = kCAFillModeBackwards;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
        animation.duration = 0.25;

        // Now let's update the image but disable CAAnimations so the buggy iOS 14 contents animation doesn't occur
        [CATransaction begin];
        [CATransaction setValue:(id)kCFBooleanTrue
                         forKey:kCATransactionDisableActions];
        [super setImage:image];
        [CATransaction commit];

        // Add our version of the contents animation
        [imageLayer addAnimation:animation forKey:@"contents"];
    } else {
        // iOS 13 and below don't have the glitched CABasicAnimation, so no workaround needed
        [super setImage:image];
    }
}

fb8708184's People

Contributors

abotkin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.