2 // UIScrollView+IQKeyboardManagerExtension.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
27 @available(iOSApplicationExtension, unavailable)
29 private struct AssociatedKeys {
30 static var ignoreScrollingAdjustment: Int = 0
31 static var ignoreContentInsetAdjustment: Int = 0
32 static var restoreContentOffset: Int = 0
35 @available(iOSApplicationExtension, unavailable)
37 public extension IQKeyboardExtension where Base: UIScrollView {
40 If YES, then scrollview will ignore scrolling (simply not scroll it) for adjusting textInputView position.
43 var ignoreScrollingAdjustment: Bool {
46 return objc_getAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment) as? Bool ?? false
52 objc_setAssociatedObject(base, &AssociatedKeys.ignoreScrollingAdjustment,
53 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
59 If YES, then scrollview will ignore content inset adjustment (simply not updating it) when keyboard is shown.
62 var ignoreContentInsetAdjustment: Bool {
65 return objc_getAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment) as? Bool ?? false
71 objc_setAssociatedObject(base, &AssociatedKeys.ignoreContentInsetAdjustment,
72 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
78 If we should restore scrollView contentOffset to it's initial position
80 var restoreContentOffset: Bool {
83 return objc_getAssociatedObject(base, &AssociatedKeys.restoreContentOffset) as? Bool ?? false
89 objc_setAssociatedObject(base, &AssociatedKeys.restoreContentOffset,
90 newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
96 // swiftlint:disable unused_setter_value
97 @available(iOSApplicationExtension, unavailable)
99 @objc public extension UIScrollView {
100 @available(*, unavailable, renamed: "iq.ignoreScrollingAdjustment")
101 var shouldIgnoreScrollingAdjustment: Bool {
106 @available(*, unavailable, renamed: "iq.ignoreContentInsetAdjustment")
107 var shouldIgnoreContentInsetAdjustment: Bool {
112 @available(*, unavailable, renamed: "iq.restoreContentOffset")
113 var shouldRestoreScrollViewContentOffset: Bool {
118 // swiftlint:enable unused_setter_value