前提・実現したいこと
iPhone12 mini, 13 miniでUIViewをドラッグするとViewが切れながら移動する原因を知りたい
発生している問題・エラーメッセージ
iPhone12 mini, 13 mini(画面サイズ5.4inch)のSimulatorでUIViewをドラッグして移動させると、画像のように切れながら移動する
他の端末で試したところ、切れずに動いたのは以下の画面サイズです(単位:inch)
・4.7
・5.5
・5.8
・6.1
・6.5
・6.7
該当のソースコード
ViewController.swift
Swift
import UIKit class ViewController: UIViewController { var demoView: UIView! override func viewDidLoad() { super.viewDidLoad() self.demoView = self.makeView(frame: CGRect(x: self.view.safeAreaInsets.top, y: self.view.safeAreaInsets.left + 100, width: 70, height: 70), inColor: .red) } private func makeView(frame: CGRect, inColor: UIColor) -> UIView { let newView = UIView(frame: frame) newView.backgroundColor = inColor newView.isUserInteractionEnabled = true self.view.addSubview(newView) return newView } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { guard let touchEvent = touches.first, let touchView = touchEvent.view else { return } let old = touchEvent.previousLocation(in: self.view) let new = touchEvent.location(in: self.view) touchView.frame.origin.x += (new.x - old.x) touchView.frame.origin.y += (new.y - old.y) } }
Storyboard
試したこと
Google検索してみましたが、似たような問題は見つかりませんでした
touchesMovedメソッドの移動方法が怪しいと思いましたが、特に関係ないようでした
補足情報(FW/ツールのバージョンなど)
・Xcode13
・Swift5.0
・iPhone12 mini, 13 mini Simulator
まだ回答がついていません
会員登録して回答してみよう