SharePopViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // ShareViewController.m
  3. // KeleAppProject
  4. //
  5. // Created by 熊竹 on 2018/3/5.
  6. // Copyright © 2018年 Cen Zhou. All rights reserved.
  7. //
  8. #import "SharePopViewController.h"
  9. #import <WXApi.h>
  10. @interface SharePopViewController ()
  11. @property(weak, nonatomic) IBOutlet UIView *contentView;
  12. @property(weak, nonatomic) IBOutlet UIImageView *shareWechat;
  13. @property(weak, nonatomic) IBOutlet UIImageView *shareTimeline;
  14. @end
  15. @implementation SharePopViewController
  16. - (instancetype)init {
  17. self = [super init];
  18. if (self) {
  19. self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  20. self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
  21. self.view.userInteractionEnabled = YES;
  22. }
  23. return self;
  24. }
  25. - (instancetype)initWithCoder:(NSCoder *)coder {
  26. self = [super initWithCoder:coder];
  27. if (self) {
  28. self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  29. self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
  30. self.view.userInteractionEnabled = YES;
  31. }
  32. return self;
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. self.contentView.transform = CGAffineTransformMakeTranslation(0, 164);
  37. self.shareWechat.userInteractionEnabled = YES;
  38. self.shareTimeline.userInteractionEnabled = YES;
  39. }
  40. - (void)viewWillAppear:(BOOL)animated {
  41. [super viewWillAppear:animated];
  42. [UIView animateWithDuration:0.2
  43. delay:0
  44. options:UIViewAnimationOptionCurveEaseOut
  45. animations:^{
  46. self.contentView.transform = CGAffineTransformMakeTranslation(0, 0);
  47. self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
  48. }
  49. completion:nil];
  50. }
  51. - (IBAction)cancel:(id)sender {
  52. [self dismiss];
  53. }
  54. - (IBAction)tapItem:(id)sender {
  55. if (((UITapGestureRecognizer *) sender).view.tag == 1) {
  56. [self shareToWechat:WXSceneSession withTitle:@"千模" description:@"千模" url:shareUrl(@(self.type), [[NSUserDefaults standardUserDefaults] objectForKey:@"qrcode"])];
  57. } else if (((UITapGestureRecognizer *) sender).view.tag == 2) {
  58. [self shareToWechat:WXSceneTimeline withTitle:@"千模" description:@"千模" url:shareUrl(@(self.type), [[NSUserDefaults standardUserDefaults] objectForKey:@"qrcode"])];
  59. }
  60. [self dismiss];
  61. }
  62. - (void)dismiss {
  63. [UIView animateWithDuration:0.2
  64. delay:0
  65. options:UIViewAnimationOptionCurveEaseInOut
  66. animations:^{
  67. self.contentView.transform = CGAffineTransformMakeTranslation(0, 164);
  68. self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
  69. }
  70. completion:^(BOOL finished) {
  71. [self dismissViewControllerAnimated:NO completion:nil];
  72. }];
  73. }
  74. - (void)shareToWechat:(enum WXScene)scene withTitle:(NSString *)title description:(NSString *)description url:(NSString *)url {
  75. SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
  76. req.bText = NO;
  77. req.scene = scene;
  78. WXMediaMessage *urlMessage = [WXMediaMessage message];
  79. urlMessage.title = title;
  80. urlMessage.description = description;
  81. [urlMessage setThumbImage:[UIImage imageNamed:@"AppIcon"]];
  82. WXWebpageObject *webObj = [WXWebpageObject object];
  83. webObj.webpageUrl = url;
  84. urlMessage.mediaObject = webObj;
  85. req.message = urlMessage;
  86. [WXApi sendReq:req];
  87. }
  88. /*
  89. #pragma mark - Navigation
  90. // In a storyboard-based application, you will often want to do a little preparation before navigation
  91. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  92. // Get the new view controller using [segue destinationViewController].
  93. // Pass the selected object to the new view controller.
  94. }
  95. */
  96. @end