Submit Search
使うっきゃない!iOS9で楽になったAuto Layout!
0 likes
318 views
S
SatoTakeshi
Swiftビギナーズ勉強会 第13回で発表した iOS9からのautolayout新機能
Engineering
Read more
1 of 42
Download now
Download to read offline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
More Related Content
PPTX
Androidアプリ本格開発入門 webブラウザ編
bg1 333
PDF
使うっきゃない!iOS9で楽になったAuto Layout!
SatoTakeshi
PDF
【アシアル塾】PHPオブジェクト指向再入門・第三回Exceptionクラスによる例外処理
アシアル株式会社
PDF
Yahoo! JAPANとKotlin
Shoichi Matsuda
PDF
例外設計における大罪
Takuto Wada
PDF
きちんと理解できるiOS開発〜Auto Layout編
mission:beGeek
PDF
iOS 9 Bootcamp #6 UIKit
Shingo Hiraya
PPTX
130624 auto layout
yuichi takeda
Androidアプリ本格開発入門 webブラウザ編
bg1 333
使うっきゃない!iOS9で楽になったAuto Layout!
SatoTakeshi
【アシアル塾】PHPオブジェクト指向再入門・第三回Exceptionクラスによる例外処理
アシアル株式会社
Yahoo! JAPANとKotlin
Shoichi Matsuda
例外設計における大罪
Takuto Wada
きちんと理解できるiOS開発〜Auto Layout編
mission:beGeek
iOS 9 Bootcamp #6 UIKit
Shingo Hiraya
130624 auto layout
yuichi takeda
Featured
(20)
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
PDF
2024 State of Marketing Report – by Hubspot
Marius Sescu
PDF
Everything You Need To Know About ChatGPT
Expeed Software
PDF
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
PDF
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
PDF
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
PDF
Skeleton Culture Code
Skeleton Technologies
PDF
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
PDF
Content Methodology: A Best Practices Report (Webinar)
contently
PPTX
How to Prepare For a Successful Job Search for 2024
Albert Qian
PDF
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
PDF
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
PDF
5 Public speaking tips from TED - Visualized summary
SpeakerHub
PDF
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
PDF
Getting into the tech field. what next
Tessa Mero
PDF
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
PDF
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Ad
使うっきゃない!iOS9で楽になったAuto Layout!
1.
使うっきゃない! iOS9で楽になった Auto Layout! 2016年2月20日 佐藤剛士
2.
自己紹介 【名前】 佐藤剛士 【お仕事】 前は受託IT企業でインフラの保守運用業務 今は有限会社カイカイでiOSアプリ作成 【できること】 ruby,iOS,apatch,linux(サーバー周り),Twilio Webフロント 【リリースアプリ】 YumeHoshi LillyBlocker -広告ブロックでサクサク快適Safariに!
3.
iOS開発の朝活しています beezプログラミング勉強会 https://www.facebook.com/groups/407821455988195/ 毎週木曜日7:30∼9:00電源カフェbeez渋谷店 詳解Swift改定版読書勉強会 https://www.facebook.com/groups/1543718659272111/ 毎週日曜日9:00∼11:00電源カフェbeez渋谷店
4.
iOS9になり Auto Layoutも さらに強化されました
5.
Auto Layoutの歴史 iOSのバージョンが上がるたびに使いやすくなる iOS6 ->
Auto Layout誕生 iOS7 -> Xcode5でPinとAlign機能追加 iOS8 -> Class Size誕生!
6.
Auto Layoutの歴史 iOSのバージョンが上がるたびに使いやすくなる iOS6 ->
Auto Layout誕生 iOS7 -> Xcode5でPinとAlign機能追加 iOS8 -> Class Size誕生! iOS9 -> StackView と NSLayoutAnchor
7.
Auto Layoutってなんだっけ? UIのレイアウトについて 制約を課すことでUIコンポーネントの位置とサイズを 自動的に決定する機能 ↓ Auto Layoutを使って嬉しいこと ・iPhone(4s
- 6sPlus)とiPadのレイアウト対応 ・Dynamic Type対応 ->文字の大きさをユーザーが決められる ・国際化対応 ->英語とアラビア語で文字の方向逆
8.
StackView
9.
• iOS 9.0
導入された機能 • 縦方向または横方向にViewを並べられる機能 • StackViewのサブビューとしてビューを入れれば StackViewの方で自動的にレイアウトしてくれる • 各ビューに対してAutoLayoutをそれぞれ設定しなくて もレイアウトをしてくれる! Stack View とっても楽!
10.
StackViewの使い方 imageViewを等間隔に並べる
11.
ライブラリーからStoryboadに配置
12.
StackViewのAutoLayoutを設定 トップに10 左0 右0
13.
今回はStackViewの高さを親ビューの70%の高さにする
14.
imageViewを3つ置く
15.
StackViewを選択して Attribute inspectorで distributionをFill Equallyに変更 imageViewが等間隔に並ぶ
16.
StackViewの入れ子
17.
UIコンポーネントを選 択した状態でStackView ボタンをクリックする と、選択したViewを内 包したStackViewを作 成できる
18.
入れ子を組み合わせる ことで、すこし複雑な レイアウトもできる 左図は垂直StackView の中に水平StackView を入れ子にしたもの 垂直StackView 水平StackView
19.
ちなみに。。。 iOS8までのviewを等間隔に並べる方法
20.
等間隔に並べたいView(view1,view2)とそれよりも 1つ多いスペース調整のview(spacing1,2,3)を用意す る spacing1 view1 view2 spacing2 spacing3
21.
今回は5つのviewをVertical Center in
Containerで 垂直方向中心に置く。(y軸を決定) spacing1 view1 view2 spacing2 spacing3
22.
spacingViewの横幅を全て同じ制約をつける spacing1 view1 view2 spacing2 spacing3 spacing1を選択して ctl+spacing2へドラッ グ→「Equal
Withds」 spacing1を選択して ctl+spacing3へドラッ グ→「Equal Withds」
23.
View1,View2のWHを決める →今回はWidth:70、Height:200 spacing1 view1 view2 spacing2 spacing3
24.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ① ①spacing1と superViewの間隔の制 約を追加 ①の結果↓
25.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ② ②spacing1とview1の 間隔の制約を追加 ②の結果↓
26.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ③ ③view1とspacing2の 間隔の制約を追加 ③の結果↓
27.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ④ ④spacing2とview2の 間隔の制約を追加 ④の結果↓
28.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ⑤ ⑤view2とspacing3の 間隔の制約を追加 ⑤の結果↓
29.
各viewの隣通しの間隔の制約をつけていく spacing1 view1 view2 spacing2 spacing3 ⑥ ⑥spacing3と superViewの間隔の制 約を追加 ⑥の結果↓
30.
spacing1に親ビューとの下向きの制約を追加 spacing1 view1 view2 spacing2 spacing3
31.
spacing1,spacing2,spacing3を選択 Top Edgesの制約を追加 →実践で使う場合はspacingの背景を透明にしてください spacing1 view1 view2 spacing2
spacing3
32.
この工程がiOS9からはいらなくなった!
33.
Layout Anchors
34.
Auto Layoutの原則 redViewyellowView 8 redView.Leading =
1.0 BlueView.trailing + 8.0 Item1 Attribute1 Item2 Attribute2 Constant Relationship Multiplier 一つ制約作るのに7つの要素必要
35.
NSLayoutAnchorクラス追加! redView.leadingAnchor.constraintEqualToAnchor(yellowV iew.trailingAnchor,constant: 8).active =
true Item 1 redView Attribute 1 leadingAnchor Relationship constraintEqualToAnchor Multiplier なし(デフォルト1.0) Item 2 yellowView Attribute 2 trailingAnchor Constant 8 プロパティで制約を設定できる!
36.
NSLayoutAnchorのいいところ • 型の安全性、保証がよい • 記述がしやすい •
コードが読みやすい
37.
今までのAuto Layout作成コード • NSLayoutConstraint
クラス • Auto Layoutに必要な7要素を引数で設定 • わかりやすいがコード量がおおい • Visual Format Language • Visual Format Languageという制約設定の記法を使 い設定 • 複数の制約をいっきに設定できる • 文字列で設定するので不正な記法を書いた時に分かる のは実行時のみ • 中央 えとか、マージン設定の方法がわかりにくい
38.
NSLayoutConstraint クラス let redViewLeadingConstraint
= NSLayoutConstraint(item: redView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: yellowView, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 8) self.view.addConstraint(redViewLeadingConstraint)
39.
Visual Format Language let
views = [ "redView" : redView, "yellowView" : yellowView ] let redViewHorizonConstrains = NSLayoutConstraint.constraintsWithVisualFormat(" H:|-[yellowView]-8-[redView]-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views) self.view.addConstraint(redViewHorizonConstrains )
40.
デモ • 下のレイアウトを3つの書き方でみてみます! redView yellowView 親ビュー 0
0 88 88 10 10 redView は親ビューの 幅40% の大きさ redViewと yellowView は同じ 大きさ
41.
サンプルコード https://github.com/SatoTakeshiX/AutoLayoutinios9
42.
参考URL iOS 9で追加されたNSLayoutAnchor使うと簡潔にわかりやすく間違 えずにNSLayoutConstraint(制約)が作れます【Auto Layout】 http://qiita.com/yucovin/items/4bebcc7a8b1088b374c9 Auto
Layout Guide https://developer.apple.com/library/ios/documentation/ UserExperience/Conceptual/AutolayoutPG/ ProgrammaticallyCreatingConstraints.html#//apple_ref/doc/ uid/TP40010853-CH16-SW1
Download