1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SVProgressHUDが左上に固定される場合

Posted at

SVProgressHUDがなぜか左上に表示される場合

SVProgressHUDの中心が(0, 0)になってしまうことがあるようです。
その場合の応急処置。

func application(_ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool 
{
    // Override point for customization after application launch.  

    SVProgressHUD.setOffsetFromCenter(
        UIOffset(horizontal: UIScreen.main.bounds.width/2,
                   vertical: UIScreen.main.bounds.height/2)
    )
}

オフセットを調整して中央に来るようにする。
あまりよろしくないが、急ぎの場合はこれで。

よくあるコードをSwiftで

あまり関係ないかもしれないけど、、、ずれを検出するコード

extension SVProgressHUD {

    static func adjustSVProgressHuDHudViewCenter() -> CGFloat {
        var keyboardWindow: UIWindow?
        for window in UIApplication.shared.windows {
            if window.nameOfClass == UIWindow.nameOfClass {
                keyboardWindow = window
                break
            }
        }
        
        if let keyboardWindow = keyboardWindow {
            for possibleKeyboard in keyboardWindow.subviews {
                if possibleKeyboard.nameOfClass == "UIPeripheralHostView" ||
                    possibleKeyboard.nameOfClass == "UIKeyboard"
                {
                    return possibleKeyboard.bounds.height
                }
                else {
                    if possibleKeyboard.nameOfClass == "UIInputSetContainerView" {
                        for possibleKeyboardSubview in possibleKeyboard.subviews {
                            if possibleKeyboardSubview.nameOfClass == "UIInputSetHostView" {
                                return possibleKeyboardSubview.bounds.height
                            }
                        }
                    }
                }
            }
        }
        return 0
    }
}


extension NSObject {

    static var nameOfClass: String {
        return NSStringFromClass(self).components(separatedBy: ".").last!
    }

    var nameOfClass: String {
        return NSStringFromClass(type(of: self)).components(separatedBy: ".").last!
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?