2 // IQUIScrollView+Additions.swift
3 // https://github.com/hackiftekhar/IQKeyboardManager
4 // Copyright (c) 2013-24 Iftekhar Qurashi.
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 @available(iOSApplicationExtension, unavailable)
28 private struct AssociatedKeys {
29 static var ignoreScrollingAdjustment: Int = 0
30 static var ignoreContentInsetAdjustment: Int = 0
31 static var restoreContentOffset: Int = 0
34 // swiftlint:disable identifier_name
35 // swiftlint:disable unused_setter_value
36 @available(iOSApplicationExtension, unavailable)
37 extension UIScrollView: IQKeyboardManagerCompatible {
39 // This property is explicitly written otherwise we were having
40 // compilation error when archiving
41 public var iq: IQKeyboardManagerWrapper<UIView> {
42 get { IQKeyboardManagerWrapper(self) }
46 // swiftlint:enable unused_setter_value
47 // swiftlint:enable identifier_name
49 @available(iOSApplicationExtension, unavailable)
51 public extension IQKeyboardManagerWrapper where Base: UIScrollView {
54 If YES, then scrollview will ignore scrolling (simply not scroll it) for adjusting textfield position.
57 var ignoreScrollingAdjustment: Bool {
59 return objc_getAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment) as? Bool ?? false
62 objc_setAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment,
63 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
68 If YES, then scrollview will ignore content inset adjustment (simply not updating it) when keyboard is shown.
71 var ignoreContentInsetAdjustment: Bool {
73 return objc_getAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment) as? Bool ?? false
76 objc_setAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment,
77 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
82 To set customized distance from keyboard for textField/textView. Can't be less than zero
84 var restoreContentOffset: Bool {
86 return objc_getAssociatedObject(base, &AssociatedKeys.restoreContentOffset) as? Bool ?? false
89 objc_setAssociatedObject(base, &AssociatedKeys.restoreContentOffset,
90 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
95 // swiftlint:disable unused_setter_value
96 @available(iOSApplicationExtension, unavailable)
97 @objc public extension UIScrollView {
98 @available(*, unavailable, renamed: "iq.ignoreScrollingAdjustment")
99 var shouldIgnoreScrollingAdjustment: Bool {
104 @available(*, unavailable, renamed: "iq.ignoreContentInsetAdjustment")
105 var shouldIgnoreContentInsetAdjustment: Bool {
110 @available(*, unavailable, renamed: "iq.restoreContentOffset")
111 var shouldRestoreScrollViewContentOffset: Bool {
116 // swiftlint:enable unused_setter_value