1. 程式人生 > >ios5鍵盤上新增OK按鈕

ios5鍵盤上新增OK按鈕

 非pad介面的數字鍵盤,自定義增加一個ok按鈕,在ios4上可以正確執行的,ios5上也不行了
比如說這個:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
經改進如下可以執行在ios5上正常顯示

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
            UIView* keyboard;
            for(int i=0; i<[tempWindow.subviews count]; i++) {
                keyboard = [tempWindow.subviews objectAtIndex:i];
                // keyboard view
found; add the custom button to it
                if(([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)||[[keyboard description] hasPrefix:@"<UIKeyboard"] == YES){
                    CGRect frame = CGRectMake(0.0f, 162.0f, 106.0f, 53.0f);
                    if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)){
                        frame = CGRectMake(0.0f, 116.0f, 162.0f, 53.0f);
                    }
                    [doneBt setFrame:frame];
                    [keyboard addSubview:doneBt];
                    break;
                }
            }