弹出键盘的怪事

1.刚开始,是没有出现,这个键盘,点着点着,这个键盘会慢慢出来,而且越来越高,最后消失不见。

2.ios5底下,没这事儿。好着呢。

3.第一次进这个页面,没问题,正常。


苹果的官方文档:

http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html


又发现个同病相怜的

http://stackoverflow.com/questions/12799223/keyboard-not-getting-fit-in-view-in-landscape-mode-running-on-ios-5-0-and-4-inch

貌似这个是因为版本关系,跟我也不是一回事儿。

http://stackoverflow.com/questions/9429876/block-keyboard-for-input/10864280#10864280

这是曙光吗?

看了这段代码,原来keyboard 跟视图不在同一个window。



明天去公司试试。

// my func
- (void) findKeyboard {

    // Locate non-UIWindow.
    UIWindow *keyboardWindow = nil;
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
        if (![[testWindow class] isEqual:[UIWindow class]]) {
           keyboardWindow = testWindow;
           break;
       }
    }

    // Locate UIKeyboard.  
    UIView *foundKeyboard = nil;
    for (UIView *possibleKeyboard in [keyboardWindow subviews]) {

        // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
        if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
            possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
        }                                                                                

        if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
           foundKeyboard = possibleKeyboard;
           break;
        }
    }
//add by weichao begin
    if (foundKeyboard) {
        foundKeyboard.frame=CGRectOffset(foundKeyboard.frame, 0, 100);

        NSLog(@"foundKeyboard:%@",foundKeyboard);

    }

//end }

还是没有解决问题,但是写了点代码,还是记录一下,大杀器也有不管用的时候啊,在封闭面前,或者说,在我不清楚这个机制的时候。
地下这段代码只是一个记录,时候发现与问题的最终解决无关。

/*

 

 DISPLAY A RECURSIVE VIEW HIERARCHY TREE

 

 */


// Recursively travel down the view tree, increasing the indentation level for children

- (void) dumpView: (UIView *) aView atIndent: (int) indent into:(NSMutableString *) outstring

{

for (int i =0; i < indent; i++) [outstringappendString:@"--"];

[outstringappendFormat:@"[%2d] %@ Frame:%@\n", indent, [[aViewclass] description],NSStringFromCGRect(aView.frame)];

for (UIView *viewin [aViewsubviews]) [selfdumpView:viewatIndent:indent +1into:outstring];

}


// Start the tree recursion at level 0 with the root view

- (NSString *) displayViews: (UIView *) aView

{

NSMutableString *outstring = [[NSMutableStringalloc]init];

[selfdumpView: aViewatIndent:0into:outstring];

return outstring;

}


// Show the tree

- (void) displayViews

{

NSLog(@"%@", [selfdisplayViews:self.view.window]);

}

//show the UIKeyboard

- (void) displayUIKeyboardViews

{


    

    NSArray *windowArray=[[UIApplicationsharedApplication]windows];

    NSLog(@"%@",windowArray);

    // Locate non-UIWindow.

    UIWindow *keyboardWindow =nil;

    for (UIWindow *testWindowin [[UIApplicationsharedApplication]windows]) {

        if (![[testWindowclass]isEqual:[UIWindowclass]]) {

            keyboardWindow = testWindow;

            break;

        }

    }

    if (keyboardWindow) {

       NSLog(@"%@", [selfdisplayViews: keyboardWindow]);

    }


    


    if (keyboardWindow) {

        keyboardWindow.autoresizesSubviews=NO;

    }

    

    // Locate UIKeyboard.

//    UIView* possibleKeyboard_2_0=nil;

//    UIView* possibleKeyboard_2_1=nil;

//    UIView*    UIKBDimmingVie=nil;

//    NSArray* UIKBKeyViewArray=nil;

    for (UIView *possibleKeyboardin [keyboardWindowsubviews]) {

        // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.

        if ([[possibleKeyboarddescription]hasPrefix:@"<UIPeripheralHostView"]) {

//            --[ 1] UIPeripheralHostView Frame:{{-110, 164}, {320, 216}}


            possibleKeyboard.frame=CGRectMake([self.tfX.textintegerValue], [self.tfY.textintegerValue], [self.tfHeight.textintegerValue], [self.tfHeight.textintegerValue]);

//            possibleKeyboard.frame=CGRectOffset(possibleKeyboard.frame, [self.tfX.text integerValue], [self.tfY.text integerValue]);

//            possibleKeyboard.frame=CGRectMake(0, 264, 320, 216);

//            possibleKeyboard_2_0 = [[possibleKeyboard subviews] objectAtIndex:0];

//            possibleKeyboard_2_1 = [[possibleKeyboard subviews] objectAtIndex:1];

        }

//        if ([[possibleKeyboard_2_0 description] hasPrefix:@"<UIImageView"]) {

//            possibleKeyboard_2_0.frame=CGRectMake(0, -3, 320, 3);

//        }

//        if ([[possibleKeyboard_2_1 description] hasPrefix:@"<UIKeyboardAutomatic"]) {

//            possibleKeyboard_2_1.frame=CGRectMake(0, 0, 320, 216);

//            possibleKeyboard=[[possibleKeyboard_2_1 subviews] objectAtIndex:0];

//        }

//        if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboardImpl"]) {

//            possibleKeyboard.frame=CGRectMake(0, 0, 320, 216);

//            possibleKeyboard=[[possibleKeyboard subviews] objectAtIndex:0];

//        }

//        if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboardLayoutStar"]) {

//            possibleKeyboard.frame=CGRectMake(0, 0, 320, 216);

//            possibleKeyboard=[[possibleKeyboard subviews] objectAtIndex:0];

//            UIKBDimmingVie=[[possibleKeyboard subviews] objectAtIndex:1];

//            [UIKBDimmingVie removeFromSuperview];

//        }

//        if ([[possibleKeyboard description] hasPrefix:@"<UIKBKeyplaneView"]) {

//            possibleKeyboard.frame=CGRectMake(0, 0, 320, 216);

//            UIKBKeyViewArray=[possibleKeyboard subviews] ;

//        }

//        

//        if ([[[UIKBKeyViewArray objectAtIndex:0] description] hasPrefix:@"<UIKBKeyView"]&&[UIKBKeyViewArray count]==7) {

//            

//            [[UIKBKeyViewArray objectAtIndex:0] setFrame:CGRectMake(1, 119, 40, 42)];

//            [[UIKBKeyViewArray objectAtIndex:1] setFrame:CGRectMake(279, 119, 40, 42)];

//            [[UIKBKeyViewArray objectAtIndex:2] setFrame:CGRectMake(1, 173, 38, 42)];

//            [[UIKBKeyViewArray objectAtIndex:3] setFrame:CGRectMake(41, 173, 38, 42)];

//            [[UIKBKeyViewArray objectAtIndex:4] setFrame:CGRectMake(121, 173, 118, 42)];

//            [[UIKBKeyViewArray objectAtIndex:5] setFrame:CGRectMake(241, 173, 78, 42)];

//            [[UIKBKeyViewArray objectAtIndex:6] setFrame:CGRectMake(81, 173, 38, 42)];

//        }

        

        

    }


    if (keyboardWindow) {

        NSLog(@"%@", [selfdisplayViews: keyboardWindow]);

    }


    


}




问题原因:

1.之前的同事,为了切换页面,在AppDelegate.m里面,重新 self.window.rootViewController = mySwitchViewController; 目的就是为了切换页面

2.我把它改成用  登陆页面用 presentViewController 的方式,弹出,九宫格mySwitchViewController,页面,就完事了。一切正常,至少目前看来是这样。

以后还是用navigationController吧。




经过这件事情,折腾了这么些天,有亮点收获

1.解决问题的思路:

排除法,正常路径是这样的,登陆页->九宫格-->tabbar里面的账户设置

(1)我在登陆页面,加了个按钮,登陆页->账户设置  没问题,看上去

(2)登陆页-->tabbar里面的账户设置 ->退出到登陆页 ,没问题

(3)登陆页->九宫格-->tabbar里面的账户设置->退出到九宫格->回到账户设置 有问题了

(2) 和(3),退回的方式都是一样的,应该不是这里的问题,那么肯定是弹出的方式,不对了。我在登陆页,自己重写了弹出的代码,发现,竟然是好的。看了一下,同事遗留的写法,确实不是那么科学,至少在我看来。

搞定。


看来碰到问题,还是不能用打补丁的方法,还是得从根源解决问题。如果没有头绪,可以考虑排除法,从最简单的层次逻辑开始,一步一步,抽丝剥茧,顺藤摸瓜,自然就迎刃而解了。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值