Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios: adjust ui view constraint when UIKeyboard shows #738

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ios/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
</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="contentView" destination="SS9-hV-cEA" id="IGX-hT-btt"/>
<outlet property="password" destination="pfU-fE-5kl" id="x6M-3I-sMa"/>
<outlet property="serverHost" destination="GsR-Z4-fTf" id="mJM-Ny-yXp"/>
<outlet property="serverPort" destination="1hy-kK-Mai" id="oWU-M2-gfa"/>
Expand Down
2 changes: 2 additions & 0 deletions src/ios/YassViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- (NSString*)getCipher;

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


@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 convertRect:[userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue] toView:self.view.window];

CGRect windowFrame = [self.view convertRect:self.view.window.frame toView:self.view.window];
CGFloat heightOffset = (windowFrame.size.height - keyboardEndFrame.origin.y) - self.view.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
Loading