UIKIT
extension CGRect { init(_ center:CGPoint, _ size:CGSize) { self.origin = CGPoint(x:center.x - size.width/2, y:center.y - size.height/2) self.size = size } } extension CGPoint { init(_ x:CGFloat, _ y:CGFloat) { self.x = x self.y = y } } ext…
UIViewのupdateConstraintsを上書きする。superを最後に呼ぶことを忘れない。制約の反映はsetNeedsUpdateConstraintsを呼ぶ。
途中にUIViewを挟んでそのUIViewのアスペクト比を決め、左右などを固定することで、そのUIViewに隣接する形でビューを拘束配置していけば画面の大きさが変わった際の調節ができる。
let button = UIBarButtonItem(customView:button) self.toolbarItems = [flexl, button, flexr] self.navigationController?.toolbar.barTintColor = UIColor.White self.navigationController?.setToolbarHidden(false, animated: true)
UICollectionViewを継承したクラスをつくり、layoutsubViewsで中心からコンテンツが1/4程度外れていたらContentOffSetを中央へ移動させるようにすれば良い。 let totalContentWidth = CGFloat(cellCount) * cellWidth let centerOffsetX = totalContentWidth…
自動的に文字の大きさを設定してくれる。フォントを対応するタイプを指定すれば良い。 UIFont.preferredFont(forTextStyle: .body) ストーリボードでもできる。コンテンツサイズの変更は次の通知を受ければ解る。 Notification.Name.UIContentSizeCategoryDi…
contentSizeをオブザーブして textView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil) contentSizeに変化があれば、中身を調節する。 override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NS…
水平な線形レイアウトで隙間を調整したい時、しかもminimumをなくしたいと考えた時、ラインも修正すると良い。
セクションは流れていく。それを止めるには stackoverflow.com
resizableSnapshotView これとUIView.transitionを組み合わせて一部分の画面遷移を再現できる。
viewWillLayoutSubviewsはviewのlayoutSubviewsの前に呼ばれる。 ちなみにlayoutSubviewsはレイアウト更新タイミング、制約つけたいときはupdateConstraints。viewWillLayoutSubviewsは結果的にViewWillAppearとViewWillDidAppearの中間で呼ばれることになる…
ビューの遷移を真似たい場合snapshotViewとtransitionをくみあわせる。 let currentView = self.view.snapshotView(afterScreenUpdates: true)! self.view.addSubview(currentView) setup() UIView.transition(with: currentView, duration: 0.5, options: […
class PushAnimator : NSObject, UIViewControllerAnimatedTransitioning { func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 1.0 } func animateTransition(using transitionContext: U…
制約更新 updateConstraintsIfNeeded() → updateConstraints()が呼ばれる。 フレーム更新 layoutIfNeeded() → layoutSubViews()が呼ばれる。 端末回転によるフレーム変更、UIScrollViewでcontentOffsetの変更時等 レンダリング setNeedsDisplay() → drawRect…
基本は A = aB + b の連立方程式を解く。 Alignment Rectangle (外接矩形) 装飾(影、角丸等)を除いたビュー。AutoLayoutはフレームではなくAlignment Rectangleを用いている。 Alignment Rectangleの表示方法 Edit Scheme のRunのArgumentで起動オプションと…
Adaptive Layout = レスポンシブレイアウトiPhoneとiPadという端末の区別はない。 どのようなウィンドウサイズでもレイアウトを維持する。 二つのポイント1. AutoLayout 2. トレイトコレクション サイズクラスはトレイトコレクションに含まれる値の一つ サイ…
UITraitCollection デバイスの情報が入っている。 Size class (H,V) iphone/ipad 倍率 Size Class 以下を参考 qiita.com 各種UI部品のUITaraitCollectionでの変化 以下を参考 qiita.com UISplitViewController Master/Detailの両方が見える時、Masterだけが…
一部のみ。つかったことないものとか。 iOS9から UIStackView iOS8から Unified Storyboardsというpad,phone共通で一つという考え UITraitCollection SizeClasses UIVisualEffectView UIImageAsset UIInputViewController カスタムキーボード UIPresentation…