Tôi muốn tạo ra file đính kèm xem, mà những nơi dưới đầu vào xem phụ kiện, trên bàn phím, giống như trong Skype App hoặc Viber:Hiện UIView với các nút trên bàn phím, giống như trong Skype, Viber sứ giả (Swift, iOS)
Tôi đã hỏi câu hỏi này here, nhưng giải pháp đề xuất cho câu hỏi này không quá thanh lịch, vì khi tôi kéo chế độ xem cuộn lên trên cùng, tôi muốn phần đính kèm UIView chuyển xuống bằng bàn phím (tôi sử dụng UIScrollViewKeyboardDismissModeInteractive).
Vì vậy, tôi tạo ra một chức năng, mà tìm hiểu xem, nơi bàn phím và tùy chỉnh xem phụ kiện đầu vào của tôi được đặt:
func findKeyboardView() -> UIView? {
var result: UIView? = nil
let windows = UIApplication.sharedApplication().windows
for window in windows {
if window.description.hasPrefix("<UITextEffectsWindow") {
for subview in window.subviews {
if subview.description.hasPrefix("<UIInputSetContainerView") {
for sv in subview.subviews {
if sv.description.hasPrefix("<UIInputSetHostView") {
result = sv as? UIView
break
}
}
break
}
}
break
}
}
return result
}
Và sau đó tôi thêm một tùy chỉnh của tôi UIView và tạo một vài ràng buộc:
func createAttachView() {
attach = MessageChatAttachmentsView(frame: CGRectZero)
let newView = findKeyboardView()
newView!.addSubview(attach!)
newView!.addConstraint(NSLayoutConstraint(item: accessoryView, attribute: .Bottom, relatedBy: .Equal, toItem: attach!, attribute: .Top, multiplier: 1.0, constant: 0.0))
attach!.addConstraint(NSLayoutConstraint(item: attach!, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 260))
attach!.addConstraint(NSLayoutConstraint(item: attach!, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 320))
}
Điều này tạo tùy chỉnh UIView dưới chế độ xem phụ kiện đầu vào và bàn phím phía trên và nó di chuyển khi tôi cuộn lên. Nhưng khi tôi muốn nhấn vào nút, tôi nhấn một phím trên bàn phím.
Vì vậy, làm thế nào tôi có thể di chuyển điểm này đến đỉnh điểm hệ thống phân cấp trong UIInputSetHostView?
Tôi nghĩ bạn nên trao đổi trong một 'inputView' mới và tải lại chế độ xem đầu vào. https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html –