Disabling keys on keyboard

前端 未结 3 1483
栀梦
栀梦 2021-02-04 15:22

I am new to Objective-C, and I am looking to limit a user from switching from the alphabet portion of a normal keyboard to the numeric/punctuation side. This being said, I would

3条回答
  •  梦谈多话
    2021-02-04 16:00

    I implemented a neater solution. The trick is to place a disabled key image on top of the keyboard.

    To do this

    1. Run emulator (in 100% scale) and screen grab the asset you'd like (in my case, this was a disabled Done button at the bottom right end)
    2. Place this image on top of the keyboard

    Note that keyboard is placed in a separate UIWindow (since iOS5 I believe) and thus, you will need to do the following

    + (void) addSubviewToTop:(UIView *)view {
         int count = [[[UIApplication sharedApplication] windows] count];
         if(count <= 0)  {
            warn(@"addSubviewToTop failed to access application windows");
         }
         UIWindow *top_window = [[[UIApplication sharedApplication] windows] objectAtIndex:count-1];
         [top_window addSubview:view];
         [top_window bringSubviewToFront:view];
    }
    

提交回复
热议问题