Skip to content

Commit

Permalink
ios: adjust ui view constraint when UIKeyboard shows
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Feb 7, 2024
1 parent fabd482 commit d148b9d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ios/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
</constraints>
</view>
<connections>
<outlet property="bottomConstraint" destination="jt2-ZP-qgJ" id="nnY-MI-aZ1"/>
<outlet property="cipherMethod" destination="lHf-f6-QZT" id="8Z3-eA-8Al"/>
<outlet property="password" destination="pfU-fE-5kl" id="x6M-3I-sMa"/>
<outlet property="serverHost" destination="GsR-Z4-fTf" id="mJM-Ny-yXp"/>
Expand Down
1 change: 1 addition & 0 deletions src/ios/YassViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- (NSString*)getCipher;

@property (weak, nonatomic) IBOutlet UILabel *status;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;


@end
Expand Down
25 changes: 25 additions & 0 deletions src/ios/YassViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ - (void)viewWillAppear:(BOOL)animated {
YassAppDelegate* appDelegate =
(YassAppDelegate*)UIApplication.sharedApplication.delegate;
[appDelegate reloadState];
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notification) {
NSDictionary *userInfo = notification.userInfo;
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect keyboardEndFrame = [self.view.superview convertRect:[userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue] toView:self.view.window];

CGRect windowFrame = [self.view.superview convertRect:self.view.window.frame toView:self.view.window];
CGFloat heightOffset = (windowFrame.size.height - keyboardEndFrame.origin.y) - self.view.superview.frame.origin.y;

self.bottomConstraint.constant = heightOffset + 20;

[UIView animateWithDuration:duration
animations:^{
[self.view layoutIfNeeded];
}];
}];

[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notification) {
NSDictionary *userInfo = notification.userInfo;
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
self.bottomConstraint.constant = 20;
[UIView animateWithDuration:duration
animations:^{
[self.view layoutIfNeeded];
}];
}];
[super viewWillAppear:animated];
}

Expand Down

0 comments on commit d148b9d

Please sign in to comment.