最近在做計(jì)算器功能時(shí),要實(shí)現(xiàn)自定義的鍵盤操作学少,所以要隱藏系統(tǒng)鍵盤剪个,完全不顯示。
寫完這一段代碼之后
for (id item in [self.viewOfInput subviews])
{
if ([item isKindOfClass:[UITextField class]])
{
UIView *temp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
((UITextField *)item).inputAccessoryView = temp;
((UITextField *)item).inputView = temp;
}else{
for (id subItem in [item subviews]) {
if ([subItem isKindOfClass:[UITextField class]])
{
UIView *temp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
((UITextField *)subItem).inputAccessoryView = temp;
((UITextField *)subItem).inputView = temp;
}
}
}
}
發(fā)現(xiàn)一個(gè)十分奇怪的問題版确,同意操作系統(tǒng)在iPhone 7及其他較小屏幕尺寸時(shí)扣囊,上述代碼正常運(yùn)行乎折。但是在plus以及X尺寸機(jī)型運(yùn)行時(shí),會(huì)導(dǎo)致崩潰侵歇,且斷點(diǎn)無法定位到具體位置骂澄。
最終在不斷探索中找到了原因,并進(jìn)行了修改惕虑。修改代碼如下:
for (id item in [self.viewOfInput subviews]){
if ([item isKindOfClass:[UITextField class]])
{
((UITextField *)item).inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
((UITextField *)item).inputView = [[UIView alloc] initWithFrame:CGRectZero];
}else{
for (id subItem in [item subviews]) {
if ([subItem isKindOfClass:[UITextField class]])
{
((UITextField *)subItem).inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
((UITextField *)subItem).inputView = [[UIView alloc] initWithFrame:CGRectZero];
}
}
}
}
發(fā)現(xiàn)的問題就是坟冲,不能將inputAccessoryView 和 inputView 的view設(shè)置為同一對象,這樣會(huì)導(dǎo)致在plus以及X尺寸機(jī)型運(yùn)行時(shí)崩潰枷遂,其他尺寸無影響
因?yàn)轫?xiàng)目比較趕,所以具體原因沒有找到棋嘲,暫時(shí)這么修改酒唉。后續(xù)原因我會(huì)繼續(xù)探索。