LoadingView.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // LoadingView.m
  3. // 米兰港
  4. //
  5. // Created by 隋林栋 on 15/3/5.
  6. // Copyright (c) 2015年 Sl. All rights reserved.
  7. //
  8. #import "LoadingView.h"
  9. @implementation LoadingView
  10. - (instancetype)initWithFrame:(CGRect)frame{
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. [self addSubview:self.imageLoading];
  14. self.imageLoading.center = CGPointMake(self.width/2.0, self.height/2.0);
  15. self.userInteractionEnabled = true;
  16. }
  17. return self;
  18. }
  19. - (UIImageView *)imageLoading{
  20. if (!_imageLoading) {
  21. _imageLoading = [UIImageView new];
  22. _imageLoading.image = [UIImage imageNamed:@"加载中"];
  23. _imageLoading.widthHeight = XY(W(34), W(34));
  24. }
  25. return _imageLoading;
  26. }
  27. - (void)resetFrame:(CGRect)frame viewShow:(UIView *)viewShow{
  28. self.frame = frame;
  29. self.imageLoading.centerXCenterY = XY(self.width/2.0, self.height/2.0-W(30));
  30. [viewShow addSubview:self];
  31. [self beginAnimate];
  32. }
  33. - (void)hideLoading{
  34. [self stopAnimate];
  35. [self removeFromSuperview];
  36. }
  37. #pragma mark Animate
  38. //begin animate
  39. - (void)beginAnimate{
  40. [self stopAnimate];
  41. CABasicAnimation * animate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
  42. animate.toValue = @(M_PI*2);
  43. [animate setRepeatCount:MAXFLOAT];
  44. [animate setDuration:2];
  45. [animate setRemovedOnCompletion:true];
  46. [self.imageLoading.layer addAnimation:animate forKey:@"animated"];
  47. }
  48. //stop animate
  49. - (void)stopAnimate{
  50. [self.imageLoading.layer removeAllAnimations];
  51. }
  52. @end