MGSaveHeadImgViewController.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // MGSaveHeadImgViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2020/6/11.
  6. // Copyright © 2020 xfg. All rights reserved.
  7. //
  8. #import "MGSaveHeadImgViewController.h"
  9. #import "TZImageManager.h"
  10. @interface MGSaveHeadImgViewController ()
  11. @property(nonatomic, strong) UIButton *backBtn;
  12. @property(nonatomic, strong) UIImageView *headImgView;
  13. @property(nonatomic, strong) UIButton *saveBtn;
  14. @end
  15. @implementation MGSaveHeadImgViewController
  16. -(instancetype)initWithHeadImageWithImage:(UIImage *)image{
  17. MGSaveHeadImgViewController *vc = [MGSaveHeadImgViewController new];
  18. vc.headImage = image;
  19. return vc;
  20. }
  21. - (void)viewWillAppear:(BOOL)animated {
  22. [super viewWillAppear:animated];
  23. self.navigationController.navigationBarHidden = YES;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  29. [self.backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back_2"] forState:UIControlStateNormal];
  30. [self.backBtn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
  31. self.backBtn.frame = CGRectMake(15, kStatusBarHeight + 5, kRealValue(30), kRealValue(30));
  32. self.headImgView.contentMode = UIViewContentModeScaleAspectFill;
  33. self.headImgView.clipsToBounds = YES;
  34. self.headImgView = [UIImageView new];
  35. self.headImgView.frame = CGRectMake(0, 0, kScreenW, kRealValue(250));
  36. self.headImgView.image = self.headImage;
  37. self.saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  38. [self.saveBtn setTitle:ASLocalizedString(@"保存")forState:UIControlStateNormal];
  39. [self.saveBtn addTarget:self action:@selector(saveHeadImage:) forControlEvents:UIControlEventTouchUpInside];
  40. self.saveBtn.backgroundColor = kAppNewMainColor;
  41. self.saveBtn.layer.cornerRadius = kRealValue(40 / 2);
  42. self.saveBtn.layer.masksToBounds = YES;
  43. self.saveBtn.frame = CGRectMake(kRealValue(30), kScreenH - kRealValue(30) - kRealValue(80), kScreenW - kRealValue(30 * 2), kRealValue(40));
  44. [self.view addSubview:self.saveBtn];
  45. [self.view addSubview:self.headImgView];
  46. [self.view addSubview:self.backBtn];
  47. }
  48. -(void)clickBack:(UIButton *)sender{
  49. // [self.navigationController popViewControllerAnimated:YES];
  50. if (self.navigationController.viewControllers.count >1)
  51. {
  52. [self.navigationController popViewControllerAnimated:YES];
  53. }else
  54. {
  55. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  56. }
  57. }
  58. -(void)saveHeadImage:(UIButton *)sender{
  59. [[TZImageManager manager] savePhotoWithImage:self.headImage completion:^(PHAsset *asset, NSError *error) {
  60. if (!error) {
  61. [FanweMessage alertHUD:ASLocalizedString(@"保存头像成功!")];
  62. }else{
  63. [FanweMessage alertHUD:error.localizedDescription];
  64. }
  65. }];
  66. }
  67. /*
  68. #pragma mark - Navigation
  69. // In a storyboard-based application, you will often want to do a little preparation before navigation
  70. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  71. // Get the new view controller using [segue destinationViewController].
  72. // Pass the selected object to the new view controller.
  73. }
  74. */
  75. @end