InterfaceController.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "InterfaceController.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
  11. @interface InterfaceController()
  12. @property (weak) IBOutlet WKInterfaceImage *imageInterface;
  13. @end
  14. @implementation InterfaceController
  15. - (void)awakeWithContext:(id)context {
  16. [super awakeWithContext:context];
  17. // Configure interface objects here.
  18. [[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
  19. }
  20. - (void)willActivate {
  21. // This method is called when watch view controller is about to be visible to user
  22. [super willActivate];
  23. NSString *urlString = @"http://apng.onevcat.com/assets/elephant.png";
  24. WKInterfaceImage *imageInterface = self.imageInterface;
  25. [imageInterface sd_setImageWithURL:[NSURL URLWithString:urlString] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  26. // `WKInterfaceImage` unlike `UIImageView`. Even the image is animated image, you should explicitly call `startAnimating` to play animation.
  27. [imageInterface startAnimating];
  28. }];
  29. }
  30. - (void)didDeactivate {
  31. // This method is called when watch view controller is no longer visible
  32. [super didDeactivate];
  33. }
  34. @end