1

I created a social media app, and I would like to enhance the UX. For that, I would like to create an animation when an image is loading. I would like to produce the same effect that we can see on Facebook for example

enter image description here

We don't really see it (only on profile image pictures), and I don't even know how I could describe it (I'm not an English native). It's like a flash from the left to the right.

I have no idea about how I could do it. Someone has an idea?

KevinB
  • 2,454
  • 3
  • 25
  • 49

1 Answers1

3

Facebook actually has a handy library to help with this: https://github.com/facebook/Shimmer

From the github page's README, it's as simple as:

FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] 
initWithFrame:self.view.bounds];
[self.view addSubview:shimmeringView];

UILabel *loadingLabel = [[UILabel alloc] 
initWithFrame:shimmeringView.bounds];
loadingLabel.textAlignment = NSTextAlignmentCenter;
loadingLabel.text = NSLocalizedString(@"Shimmer", nil);
shimmeringView.contentView = loadingLabel;

// Start shimmering.
shimmeringView.shimmering = YES;

The main thing you'd have to do is change the above code from using a UILabel to whatever UIImageView is being used for your profile images. Good luck!

BHendricks
  • 4,423
  • 6
  • 32
  • 59
  • Wow that's exactly what I'm looking for! But it seems to be in Objective-C, can I use it with Swift? (Sorry I'm new with swift dev) – KevinB Apr 12 '18 at 17:59
  • 1
    Yes you can! Check out this other SO question/answer on that topic: https://stackoverflow.com/questions/31884507/how-to-use-objective-c-cocoapods-in-a-swift-project -- should be as simple as adding any other Cocoapod as long as you have `use_frameworks!` in your Podfile – BHendricks Apr 12 '18 at 18:01
  • If I have more than 1 Objective-C pod, do I have to write every time I add an Objective-c pod? – KevinB Apr 12 '18 at 18:07
  • 1
    No, it's a once per Podfile type of flag :) – BHendricks Apr 12 '18 at 18:08
  • The example of adding Shimmer to a label is in Objective-C, does anyone knows how to implement this code for swift 5? – Zita Noriega Estrada Feb 25 '20 at 15:46