NIMCreateTeamAnnouncement.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // NTESCreateTeamAnnouncement.m
  3. // NIM
  4. //
  5. // Created by Xuhui on 15/3/31.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMCreateTeamAnnouncement.h"
  9. #import "UIView+NIM.h"
  10. #import "NIMGlobalMacro.h"
  11. #import "NIMKitKeyboardInfo.h"
  12. @interface NIMCreateTeamAnnouncement () <UITextFieldDelegate, UITextViewDelegate>
  13. @property (strong, nonatomic) UITextField *titleTextField;
  14. @property (strong, nonatomic) UITextView *contentTextView;
  15. @property (nonatomic,strong) UIScrollView *scrollView;
  16. @end
  17. @implementation NIMCreateTeamAnnouncement
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.navigationItem.title = @"新建群公告";
  21. self.view.backgroundColor = LCBkgColor;
  22. self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
  23. self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  24. [self.view addSubview:self.scrollView];
  25. UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 42, self.view.nim_width, 51)];
  26. titleView.backgroundColor = [UIColor whiteColor];
  27. titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  28. [self.scrollView addSubview:titleView];
  29. CGFloat padding = 20.f;
  30. CGFloat contentWidth = self.view.nim_width - padding;
  31. self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 11, contentWidth, 30)];
  32. self.titleTextField.placeholder = @"标题";
  33. self.titleTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  34. self.titleTextField.font = [UIFont systemFontOfSize:17.f];
  35. self.titleTextField.textColor = [UIColor grayColor];
  36. self.titleTextField.text = self.defaultTitle;
  37. self.titleTextField.delegate = self;
  38. [titleView addSubview:self.titleTextField];
  39. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 134, self.view.nim_width, 140)];
  40. contentView.backgroundColor = [UIColor whiteColor];
  41. contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  42. [self.scrollView addSubview:contentView];
  43. self.contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(15, 17, contentWidth, 106)];
  44. self.contentTextView.textColor = [UIColor blackColor];
  45. self.contentTextView.font = [UIFont systemFontOfSize:17.f];
  46. self.contentTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  47. self.contentTextView.delegate = self;
  48. self.contentTextView.text = self.defaultContent;
  49. [contentView addSubview:self.contentTextView];
  50. self.edgesForExtendedLayout = UIRectEdgeNone;
  51. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(onSave:)];
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:NIMKitKeyboardWillChangeFrameNotification object:nil];
  53. }
  54. - (void)dealloc{
  55. [[NSNotificationCenter defaultCenter] removeObserver:self];
  56. }
  57. - (void)keyboardWillChangeFrame:(NSNotification*)notification{
  58. NSDictionary* userInfo = [notification userInfo];
  59. CGRect keyboardFrame;
  60. [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
  61. CGFloat keyBordOriginY = keyboardFrame.origin.y;
  62. BOOL iOS7 = ([[[UIDevice currentDevice] systemVersion] doubleValue] < 8.0);
  63. UIInterfaceOrientation orientation =
  64. [[UIApplication sharedApplication] statusBarOrientation];
  65. if (iOS7 && (orientation == UIDeviceOrientationLandscapeLeft
  66. || orientation == UIDeviceOrientationLandscapeRight)) {
  67. keyBordOriginY = keyboardFrame.origin.x + keyboardFrame.size.width;
  68. }
  69. self.scrollView.nim_height = keyBordOriginY - self.navigationController.navigationBar.nim_bottom;
  70. self.scrollView.nim_width = self.view.nim_width;
  71. self.scrollView.contentSize = CGSizeMake(self.view.nim_width, self.contentTextView.superview.nim_bottom);
  72. self.scrollView.nim_top = 0;
  73. }
  74. - (void)viewWillDisappear:(BOOL)animated {
  75. [super viewWillDisappear:animated];
  76. [self.titleTextField endEditing:YES];
  77. [self.contentTextView endEditing:YES];
  78. }
  79. - (void)onSave:(id)sender {
  80. [self.titleTextField endEditing:YES];
  81. [self.contentTextView endEditing:YES];
  82. NSString *title = [self.titleTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  83. NSString *content = [self.contentTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  84. [self.navigationController popViewControllerAnimated:YES];
  85. if([self.delegate respondsToSelector:@selector(createTeamAnnouncementCompleteWithTitle:content:)]) {
  86. [self.delegate createTeamAnnouncementCompleteWithTitle:title content:content];
  87. }
  88. }
  89. - (BOOL)shouldAutorotate{
  90. return NO;
  91. }
  92. #pragma mark - 旋转处理 (iOS8 or above)
  93. - (void)viewWillTransitionToSize:(CGSize)size
  94. withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  95. {
  96. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  97. [self.view endEditing:YES];
  98. }
  99. @end