ios - ReactiveCocoa : Handling Multiple Unbalanced Keyboard Notifications
<p><p>我正在使用 Reactive Cocoa 构建一个示例身份验证 ViewController 。我知道如何以 react 方式设置和接收来自键盘的通知。但是,我收到不平衡的 UP 和 DOWN 通知。正因为如此,我必须设置一个 BOOL 变量来查看键盘之前是否已经抬起但没有放下。有没有办法被动地做到这一点?完整的项目是<a href="https://github.com/rismay/AuthController/blob/master/AuthController/WSMAuthViewController.m" rel="noreferrer noopener nofollow">here</a> .</p>
<pre><code>- (void)configureKeyboardAnimations {
CGFloat duration = 0.9, damping = 0.8;
@weakify(self);
[[[NSNotificationCenter.defaultCenter rac_addObserverForName:UIKeyboardWillShowNotification
object:nil]
takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *notification) {
@strongify(self);
if (!self.tableViewOffset) {
CGRect keyboardRect = CGRectValue];
[UIView animateWithDuration:duration delay:0 usingSpringWithDamping:damping
initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
self.tableView.frame = CGRectOffset(self.tableView.frame, 0,
-CGRectGetHeight(keyboardRect));
} completion:^(BOOL finished) {}];
self.tableViewOffset = YES; //I need this set immediately not at completion.
}
}];
[[[NSNotificationCenter.defaultCenter rac_addObserverForName:UIKeyboardWillHideNotification
object:nil]
takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *notification) {
@strongify(self);
CGRect keyboardRect = CGRectValue];
[UIView animateWithDuration:duration delay:0 usingSpringWithDamping:damping
initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
self.tableView.frame = CGRectOffset(self.tableView.frame, 0,
CGRectGetHeight(keyboardRect));
} completion:^(BOOL finished) {}];
self.tableViewOffset = NO; //I need this set immediately not at completion.
}];
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我想我已经为你找到了解决方案。可能不是最简单的,但它会起作用,我觉得这是一种解决问题的“ReactiveCocoa”方式。 </p>
<pre><code>RACSignal *keyboardShowSignal = [ takeUntil:self.rac_willDeallocSignal];
RACSignal *keyboardHideSignal = [ takeUntil:self.rac_willDeallocSignal];
RACSignal *latestNotification = ];
[[[latestNotification map:^id(NSNotification *notification) {
return notification.userInfo;
}] distinctUntilChanged] subscribeNext:^(NSNumber *rectNumber) {
// Animate things here with
}];
RAC(self, tableViewOffset) = [[[latestNotification map:^id(NSNotification *notification) {
return @();
}] distinctUntilChanged] startWith:@(NO)];
</code></pre>
<p>完整的项目是<a href="http://cloud.ashfurrow.com/31270p2S3h05" rel="noreferrer noopener nofollow">here</a> .</p></p>
<p style="font-size: 20px;">关于ios - ReactiveCocoa : Handling Multiple Unbalanced Keyboard Notifications,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26370360/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26370360/
</a>
</p>
页:
[1]