TUICaptureImagePreviewController.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Created by Tencent on 2023/06/09.
  2. // Copyright © 2023 Tencent. All rights reserved.
  3. #import "TUICaptureImagePreviewController.h"
  4. #import <TIMCommon/TIMCommonModel.h>
  5. #import <TIMCommon/TIMDefine.h>
  6. @interface TUICaptureImagePreviewController () {
  7. UIImage *_image;
  8. }
  9. @property(nonatomic) UIImageView *imageView;
  10. @property(nonatomic) UIButton *commitButton;
  11. @property(nonatomic) UIButton *cancelButton;
  12. @property(nonatomic) CGRect lastRect;
  13. @end
  14. @implementation TUICaptureImagePreviewController
  15. - (instancetype)initWithImage:(UIImage *)image {
  16. if (self = [super initWithNibName:nil bundle:nil]) {
  17. _image = image;
  18. }
  19. return self;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor blackColor];
  24. UIImageView *imageView = [[UIImageView alloc] initWithImage:_image];
  25. imageView.layer.masksToBounds = YES;
  26. imageView.contentMode = UIViewContentModeScaleAspectFit;
  27. [self.view addSubview:imageView];
  28. self.imageView = imageView;
  29. NSLog(@"%ld--%ld", (long)_image.imageOrientation, UIImageOrientationUp);
  30. self.commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
  31. UIImage *commitImage = [[TUIImageCache sharedInstance] getResourceFromCache:TUIChatImagePath(@"camer_commit")];
  32. [self.commitButton setImage:commitImage forState:UIControlStateNormal];
  33. UIImage *commitBGImage = [[TUIImageCache sharedInstance] getResourceFromCache:TUIChatImagePath(@"camer_commitBg")];
  34. [self.commitButton setBackgroundImage:commitBGImage forState:UIControlStateNormal];
  35. [self.commitButton addTarget:self action:@selector(commitButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  36. [self.view addSubview:self.commitButton];
  37. self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
  38. UIImage *cancelButtonBGImage = [[TUIImageCache sharedInstance] getResourceFromCache:TUIChatImagePath(@"camera_cancel")];
  39. [self.cancelButton setBackgroundImage:cancelButtonBGImage forState:UIControlStateNormal];
  40. [self.cancelButton addTarget:self action:@selector(cancelButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  41. [self.view addSubview:self.cancelButton];
  42. }
  43. - (void)viewWillLayoutSubviews {
  44. [super viewWillLayoutSubviews];
  45. if (!CGRectEqualToRect(self.lastRect, self.view.bounds)) {
  46. self.lastRect = self.view.bounds;
  47. self.imageView.frame = self.view.bounds;
  48. CGFloat commitButtonWidth = 80.0;
  49. CGFloat buttonDistance = (self.view.bounds.size.width - 2 * commitButtonWidth) / 3.0;
  50. CGFloat commitButtonY = self.view.bounds.size.height - commitButtonWidth - 50.0;
  51. CGFloat commitButtonX = 2 * buttonDistance + commitButtonWidth;
  52. self.commitButton.frame = CGRectMake(commitButtonX, commitButtonY, commitButtonWidth, commitButtonWidth);
  53. CGFloat cancelButtonX = commitButtonWidth;
  54. self.cancelButton.frame = CGRectMake(cancelButtonX, commitButtonY, commitButtonWidth, commitButtonWidth);
  55. if (isRTL()) {
  56. [self.commitButton resetFrameToFitRTL];
  57. [self.cancelButton resetFrameToFitRTL];
  58. }
  59. }
  60. }
  61. - (void)commitButtonClick:(UIButton *)btn {
  62. if (self.commitBlock) {
  63. self.commitBlock();
  64. }
  65. }
  66. - (void)cancelButtonClick:(UIButton *)btn {
  67. if (self.cancelBlock) {
  68. self.cancelBlock();
  69. }
  70. }
  71. @end