亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以編程方式檢查iOS應用程序中是否存在鍵盤?

如何以編程方式檢查iOS應用程序中是否存在鍵盤?

iOS
BIG陽 2019-11-08 14:22:00
我需要在我的iOS應用中檢查鍵盤可見性的條件。偽代碼:if(keyboardIsPresentOnWindow) {    //Do action 1}else if (keyboardIsNotPresentOnWindow) {    //Do action 2}如何檢查這種情況?
查看完整描述

3 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

…或采取簡單的方法:


輸入textField時,它成為第一響應者,并出現鍵盤。您可以使用來檢查鍵盤的狀態[myTextField isFirstResponder]。如果返回YES,則鍵盤處于活動狀態。


查看完整回答
反對 回復 2019-11-08
?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

drawonward的代碼非常接近,但與UIKit的命名空間沖突,因此可以更易于使用。


@interface KeyboardStateListener : NSObject {

    BOOL _isVisible;

}

+ (KeyboardStateListener *)sharedInstance;

@property (nonatomic, readonly, getter=isVisible) BOOL visible;

@end


static KeyboardStateListener *sharedInstance;


@implementation KeyboardStateListener


+ (KeyboardStateListener *)sharedInstance

{

    return sharedInstance;

}


+ (void)load

{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    sharedInstance = [[self alloc] init];

    [pool release];

}


- (BOOL)isVisible

{

    return _isVisible;

}


- (void)didShow

{

    _isVisible = YES;

}


- (void)didHide

{

    _isVisible = NO;

}


- (id)init

{

    if ((self = [super init])) {

        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

        [center addObserver:self selector:@selector(didShow) name:UIKeyboardDidShowNotification object:nil];

        [center addObserver:self selector:@selector(didHide) name:UIKeyboardWillHideNotification object:nil];

    }

    return self;

}


@end


查看完整回答
反對 回復 2019-11-08
?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

UIKeyboardListener當您知道鍵盤不可見時,請創建一個,例如通過[UIKeyboardListener shared]從調用applicationDidFinishLaunching。


@implementation UIKeyboardListener


+ (UIKeyboardListener) shared {

    static UIKeyboardListener sListener;    

    if ( nil == sListener ) sListener = [[UIKeyboardListener alloc] init];


    return sListener;

}


-(id) init {

    self = [super init];


    if ( self ) {

        NSNotificationCenter        *center = [NSNotificationCenter defaultCenter];

        [center addObserver:self selector:@selector(noticeShowKeyboard:) name:UIKeyboardDidShowNotification object:nil];

        [center addObserver:self selector:@selector(noticeHideKeyboard:) name:UIKeyboardWillHideNotification object:nil];

    }


    return self;

}


-(void) noticeShowKeyboard:(NSNotification *)inNotification {

    _visible = true;

}


-(void) noticeHideKeyboard:(NSNotification *)inNotification {

    _visible = false;

}


-(BOOL) isVisible {

    return _visible;

}


@end


查看完整回答
反對 回復 2019-11-08
  • 3 回答
  • 0 關注
  • 547 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號