IDCreationPageViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "IDCreationPageViewController.h"
  21. #import "RectUtil.h"
  22. #import "AppDelegate.h"
  23. @interface IDCreationPageViewController ()
  24. @property UIView *infoIconView;
  25. @end
  26. @implementation IDCreationPageViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. if (SYSTEM_IS_IPAD) {
  30. CGRect mainRect = _mainContentView.frame;
  31. if ([AppDelegate hasBottomSafeAreaInsets]) {
  32. mainRect.size.height -= 20.0;
  33. }
  34. // stick to lower left corner of main view
  35. CGRect rect = [RectUtil setPositionOf:_moreView.frame x:CGRectGetMinX(mainRect) y:CGRectGetMaxY(mainRect)];
  36. _moreView.frame = rect;
  37. } else {
  38. if ([self shouldAdaptToSmallScreen]) {
  39. // e.g. iPhone 4 etc
  40. [self adaptToSmallScreen];
  41. }
  42. if ([AppDelegate hasBottomSafeAreaInsets]) {
  43. _moreView.frame = CGRectMake(_moreView.frame.origin.x, _moreView.frame.origin.y - 20.0, _moreView.frame.size.width, _moreView.frame.size.height);
  44. }
  45. }
  46. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedMoreMessage:)];
  47. [_moreView addGestureRecognizer:tapGesture];
  48. _moreView.userInteractionEnabled = YES;
  49. [_moreView.okButton addTarget:self action:@selector(tappedMoreMessage:) forControlEvents:UIControlEventTouchUpInside];
  50. }
  51. - (void)adaptToSmallScreen {
  52. CGRect rect = [RectUtil offsetRect:self.view.frame byX:0.0 byY:-28.0];
  53. self.view.frame = rect;
  54. }
  55. - (BOOL)shouldAdaptToSmallScreen {
  56. return self.view.frame.size.height < 500.0;
  57. }
  58. - (void)showMessageView:(UIView *)messageView {
  59. messageView.alpha = 0.0;
  60. messageView.hidden = NO;
  61. UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
  62. [UIView animateWithDuration:0.3 delay:0.0 options:options animations:^{
  63. _mainContentView.alpha = 0.0;
  64. messageView.alpha = 1.0;
  65. _moreView.alpha = 0.0;
  66. [self.containerDelegate hideControls:YES];
  67. } completion:^(BOOL finished) {
  68. _mainContentView.hidden = YES;
  69. messageView.hidden = NO;
  70. UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, messageView);
  71. }];
  72. }
  73. - (void)hideMessageView:(UIView *)messageView {
  74. [self hideMessageView:messageView ignoreControls:NO];
  75. }
  76. - (void)hideMessageView:(UIView *)messageView ignoreControls:(BOOL)ignoreControls {
  77. _mainContentView.alpha = 0.0;
  78. _mainContentView.hidden = NO;
  79. UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
  80. [UIView animateWithDuration:0.3 delay:0.0 options:options animations:^{
  81. messageView.alpha = 0.0;
  82. _mainContentView.alpha = 1.0;
  83. _moreView.alpha = 1.0;
  84. if (ignoreControls == NO) {
  85. [self.containerDelegate hideControls:NO];
  86. }
  87. } completion:^(BOOL finished) {
  88. messageView.hidden = YES;
  89. _mainContentView.hidden = NO;
  90. }];
  91. }
  92. #pragma mark - UITapGestureRecognizer
  93. - (void)tappedMoreMessage:(UITapGestureRecognizer *)sender
  94. {
  95. [self.containerDelegate hideControls: (_moreView.isShown == NO)];
  96. if (sender.state == UIGestureRecognizerStateEnded || [sender isKindOfClass:[UIButton class]]) {
  97. [_moreView toggle];
  98. }
  99. }
  100. @end