iPad的sizeClass

Henry Huang
2 min readJan 9, 2018

--

sizeClass是Apple因應iPhone及iPad的螢幕尺寸越來越多樣所想出來的其中一種方式,在開發iPhone時,如果要使app直立的畫面與橫放的畫面有所區別,只要稍微熟悉一下就能非常容易使用。

但在使用多次後發現,iPad不管是直立或者橫放,Apple將iPad的長與寬都設為regular,所以正常方法不管怎麼設置sizeClass,iPad的直立與橫放畫面排版都是一樣,所以就上網去找了一下資料,找到了這位的分享https://medium.com/if-let-swift-programming/size-classes-ipad-portrait-landscape-55f59173c65a

只是簡單的幾行就能讓我們使用sizeClass來讓iPad的直立與橫放有不同排版哦,以下為他的程式碼:

public class CustomTraitCollectionViewController: UIViewController {override public var traitCollection: UITraitCollection {if UIDevice.currentDevice().userInterfaceIdiom == .Pad && UIDevice.currentDevice().orientation.isPortrait.boolValue {return UITraitCollection(traitsFromCollections:[UITraitCollection(horizontalSizeClass: .Compact), UITraitCollection(verticalSizeClass: .Regular)])
}
return super.traitCollection
}
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Henry Huang
Henry Huang

Written by Henry Huang

大學讀企管/退伍後在業務圈打滾6年後突然有一天決定投入完全沒接觸過的程式設計/目前為一位iOS Developer/熱愛NBA/dafu1231@gmail.com

No responses yet

Write a response