久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 iOS 9 Shortcut Bar only 模式下,與鍵盤頂部對(duì)齊的

View aligned to top of keyboard appears in wrong place in iOS 9 Shortcut Bar only mode(在 iOS 9 Shortcut Bar only 模式下,與鍵盤頂部對(duì)齊的視圖出現(xiàn)在錯(cuò)誤的位置)
本文介紹了在 iOS 9 Shortcut Bar only 模式下,與鍵盤頂部對(duì)齊的視圖出現(xiàn)在錯(cuò)誤的位置的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

iOS 9 為 iOS 8 添加了
(注意紅色視圖是如何連接到鍵盤頂部的)

實(shí)際行為:

<塊引用>

將紅色視圖附加到鍵盤頂部的正確方法是什么?

解決方案

問題在于大多數(shù)代碼 (

當(dāng)鍵盤處于僅快捷欄模式時(shí),這是矩形:

<塊引用>

請(qǐng)注意鍵盤的大部分是如何在屏幕外的,但它仍然是相同的高度.

要獲得正確的行為,請(qǐng)使用 CGRectIntersection 與視圖的邊界和該視圖內(nèi)的鍵盤框架:

//? 好代碼,使用CGRect keyboardScreenEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];CGRect keyboardViewEndFrame = [self.view convertRect:keyboardScreenEndFrame fromView:self.view.window];CGRect keyboardFrame = CGRectIntersection(self.view.bounds, keyboardViewEndFrame);CGFloat keyboardHeight = keyboardFrame.size.height;//= 55

出于同樣的原因,應(yīng)該使用 UIKeyboardFrameEndUserInfoKey 而不是 UIKeyboardFrameBeginUserInfoKey.

iOS 9 adds a Shortcut Bar to the iOS 8 QuickType bar.

As part of this change, if you connect a bluetooth keyboard to an iPad, the keyboard is in a minimized Shortcut Bar only mode (which can be simulated by pressing command-k in the simulator).

I have code which gets the keyboard height using a method similar to the following:

CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height; // = 313

The problem is that when the keyboard is toggled between the expanded and collapsed state, the height remains the same, causing my view to appear in its old location:

Desired behavior:


(Notice how the red view is attached to the top of the keyboard)

Actual behavior:

What's the correct way to get the red view to be attached to the top of the keyboard?

解決方案

The problem is that most code out there (including Apple's) ignores the fact that UIKeyboardFrameEndUserInfoKey is a CGRect and not a CGSize.

// ? Bad code, do not use
- (void)keyboardWasShown:(NSNotification*)aNotification {
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    CGRect bkgndRect = activeField.superview.frame;
    bkgndRect.size.height += kbSize.height;
    [activeField.superview setFrame:bkgndRect];
    [scrollView setContentOffset:CGPointMake(0.0, activeField.frame.origin.y-kbSize.height) animated:YES];
}

Here you see that only the keyboard height (kbSize.height) is being used. The origin of the rect is important, and should not be ignored.

When the keyboard is visible, this is the rect that is reported:

When the keyboard is in Shortcut Bar only mode, this is the rect:

Notice how the majority of the keyboard is offscreen, yet it is still the same height.

To get the correct behavior, use CGRectIntersection with the view's bounds and the keyboard frame within that view:

// ? Good code, use
CGRect keyboardScreenEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect keyboardViewEndFrame = [self.view convertRect:keyboardScreenEndFrame fromView:self.view.window];
CGRect keyboardFrame = CGRectIntersection(self.view.bounds, keyboardViewEndFrame);
CGFloat keyboardHeight = keyboardFrame.size.height; // = 55

For this same reason, UIKeyboardFrameEndUserInfoKey should be used as opposed to UIKeyboardFrameBeginUserInfoKey.

這篇關(guān)于在 iOS 9 Shortcut Bar only 模式下,與鍵盤頂部對(duì)齊的視圖出現(xiàn)在錯(cuò)誤的位置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw stars using Quartz Core?(如何使用 Quartz Core 繪制星星?)
Why does giving addArcWithCenter a startAngle of 0 degrees make it start at 90 degrees?(為什么給 addArcWithCenter 一個(gè) 0 度的 startAngle 使它從 90 度開始?)
Find the CGPoint on a UIView rectangle intersected by a straight line at a given angle from the center point(在與中心點(diǎn)成給定角度的直線相交的 UIView 矩形上找到 CGPoint)
Which is the best way to estimate measure of photographed things?(哪種方法是估計(jì)拍攝物體尺寸的最佳方法?)
How to convert an Int to a Character in Swift(如何在 Swift 中將 Int 轉(zhuǎn)換為字符)
How to create a hex color string UIColor initializer in Swift?(如何在 Swift 中創(chuàng)建十六進(jìn)制顏色字符串 UIColor 初始化程序?)
主站蜘蛛池模板: 亚洲欧美日韩高清 | 国产精品污www一区二区三区 | 欧美伦理一区 | 日日夜夜天天 | a免费视频 | 一区二区三区电影网 | 日日做夜夜爽毛片麻豆 | 亚洲精品一区二区三区免 | 91久久 | av大片| 精久久| 韩国av影院 | 亚洲视频在线观看 | 亚洲二区视频 | 亚洲国产精品久久久久 | 成人在线播放网址 | 美女黄18岁以下禁止观看 | 午夜影院在线观看视频 | 国产精品一区久久久 | 国产精品揄拍一区二区 | 日本a在线| 国产精品日女人 | 久久国产一区二区三区 | 一区在线视频 | 色视频网站 | 欧美精品1区 | 天天插天天射天天干 | 嫩草懂你的影院入口 | 久久亚洲一区二区三区四区 | 在线视频a | 国产精品久久久久久久久久久久久 | 久久99国产精一区二区三区 | 亚州精品天堂中文字幕 | 一本大道久久a久久精二百 国产成人免费在线 | 亚洲国产成人av好男人在线观看 | 日韩国产欧美在线观看 | 97综合在线 | 国产不卡在线 | 国产精品视频免费观看 | 久久性色| 日韩字幕一区 |