English 中文(简体)
iii
原标题:iPhone - knowing the keyboard size when it is already shown
  • 时间:2011-03-28 18:37:21
  •  标签:
  • iphone

在大韩民国,我知道,我可以使用通知(UIKey板WillShowNoification)和这份通知阅读键盘大小。

keybSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

但只有在关键板显示的情况下才能做到这一点。

但问题是: 我有一个窗口,在钥匙板上可见和当蜂窝轮时,必须调整自己。 当我轮任时,两人均代表方法将操作并处理轮任问题。 在这些方法中,我需要了解目前的关键高度,因此我可以正确看待这一看法。 问题是,在轮任后,由代表方法处理,由Fekeey板WillShowNoification通知所发射的方法。

所用方法的顺序是:

  1. willRotateToInterfaceOrientation
  2. didRotateFromInterfaceOrientation
  3. UIKeyboardWillShowNotification method

换言之,关键高度刚刚在尾读,这意味着方法1和2将使用旧的关键高度。

我的问题是:是否有办法直接阅读可见键盘的关键高度,而不是依靠通知发射的方法?

thanks

最佳回答

Variant 1

你们可以利用这一法典探索以下观点:

- (void)printSubviews:(UIView *)aView {
    NSLog(@"%@ - %@", [aView class], NSStringFromCGRect([aView frame]));
    for (UIView *view in [aView subviews]) {
        [self printSubviews:view];
    }
}


- (void)printAllViews {
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        [self printSubviews:window];
    }
}

你们认为,从你获得的价值观中抹去关键的规模非常容易。

Variant 2

Alternatively, you can import UIKeyboard.h (you can find it on the internet). It includes a method to get the default keyboard size for various interface orientations. However, that would make use of private APIs, so you might want to be careful with it.

问题回答

我在提出一个问题,即确定<条码>的内容。 当键盘已经可见时,见到。 这里,我所谈的是什么(它并不涉及任何过于 ha的解决办法)。

您的观点控制者赞同< IDKey板WillShowNoification的想法是正确的,是这样做的最佳途径。 - 不要试图以任何其他方式计算主机大小,因为(a) 键盘大小可能无法预测,(b) 您不想冒用私人标本的风险。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                          selector:@selector(keyboardWillShow:)
                                          name:UIKeyboardWillShowNotification
                                          object:nil];
}

页: 1 显示方法。 如果你重新使用<条码>,即刻板/条码<>——如我一样——你希望将由此产生的关键机体大小从<条码>中删除。 UIKey板FrameEndUserInfoKey key。

- (void)keyboardWillShow:(NSNotification *)notification {

    NSDictionary *info = [notification userInfo];
    NSTimeInterval duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey]
                               doubleValue];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] 
                           CGRectValue].size;

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication]
                                          statusBarOrientation];
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0);

    // The gotcha is that the keyboard size as reported by
    // UIKeyboardFrameEndUserInfoKey is always reported as if the device was in
    // portrait mode. I ve had to work around  that a little by setting the
    // bottom edge to the keyboard s width.
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        insets = UIEdgeInsetsMake(0, 0, keyboardSize.width, 0);
    }

    [UIView animateWithDuration:duration
                          delay:0
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
        self.gridScrollView.contentInset = insets;
        self.gridScrollView.scrollIndicatorInsets = insets;
    } completion:nil];
}

希望能帮助你们——同样,利用通知实现你想要的东西是完全可能的和安全的。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。