6
7

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 5 years have passed since last update.

UIImagaPickerControllerで強く押した時にクラッシュする

Last updated at Posted at 2015-11-12

追記:12/21 2015

もっとちゃんと直してる人がいました。
http://stackoverflow.com/questions/33331758/uiimagepickercontroller-crashing-on-force-touch
MSDPreventImagePickerCrashOn3DTouch.h
MSDPreventImagePickerCrashOn3DTouch.m
を自プロジェクトに突っ込んで、
MSDPreventImagePickerCrashOn3DTouch()
を呼ぶだけです。

追記前

UIImagePickerがまだpeekとpop(?)に対応していないらしく、3Dタッチ用のメソッドを呼ぼうとしてそんなもんねーよって怒られちゃいます
てことで、カスタムUIWindowでタッチイベントをフック&アッパー(はい、ごめんなさい。)

Movedかつforceが2ぐらいのときに呼ばれる感じだったので、こんな感じに。

class CustomWindow: UIWindow {
    override func sendEvent(event: UIEvent) {
        let touches = event.allTouches()
        if touches?.count == 1 {
            if let touch = touches?.first, _ = touch.view {
                if touch.phase == .Moved && "\(touch.view!.classForCoder)" == "PUPhotoView" {
                    if #available(iOS 9.0, *) {
                        let force = touch.force
                        if force < 1.5 {
                            super.sendEvent(event)
                        } else {
                            //  (   -з) 無視
                        }
                    } else {
                        super.sendEvent(event)
                    }
                } else {
                    super.sendEvent(event)
                }
            } else {
                super.sendEvent(event)
            }
        } else {
            super.sendEvent(event)
        }
    }
}

if..だらけだったのでごにょごにょしてこうなりました。

override fun sendEvent(event: UIEvent) {

    if #available(iOS 9.0, *) {
        if let touches = event.allTouches() where touches.count == 1 {
            if let touch = touches.first, let view = touch.view where touch.phase == .Moved && "\(view.classForCoder)" == "PUPhotoView" {
                if touch.force > 1.5 {
                    return
                }
            }
        }
    }

    super.sendEvent(event)
}

もうちょっと綺麗にならないものか、、、

6
7
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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?