This repository was archived by the owner on Jun 17, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,11 @@ open class MenuItemView: UIView {
229229 let width : CGFloat
230230 switch menuOptions. displayMode {
231231 case . segmentedControl:
232- width = UIApplication . shared. keyWindow!. bounds. size. width / CGFloat( menuOptions. itemsOptions. count)
232+ if let windowWidth = UIApplication . shared. keyWindow? . bounds. size. width {
233+ width = windowWidth / CGFloat( menuOptions. itemsOptions. count)
234+ } else {
235+ width = UIScreen . main. bounds. width / CGFloat( menuOptions. itemsOptions. count)
236+ }
233237 default :
234238 width = image. size. width + horizontalMargin * 2
235239 }
Original file line number Diff line number Diff line change @@ -56,7 +56,13 @@ open class MenuView: UIScrollView {
5656 }
5757 }
5858 fileprivate var centerOfScreenWidth : CGFloat {
59- return menuItemViews [ currentPage] . frame. midX - UIApplication. shared. keyWindow!. bounds. width / 2
59+ let screenWidth : CGFloat
60+ if let width = UIApplication . shared. keyWindow? . bounds. width {
61+ screenWidth = width
62+ } else {
63+ screenWidth = UIScreen . main. bounds. width
64+ }
65+ return menuItemViews [ currentPage] . frame. midX - screenWidth / 2
6066 }
6167 fileprivate var contentOffsetXForCurrentPage : CGFloat {
6268 guard menuItemCount > MinimumSupportedViewCount else { return 0.0 }
@@ -307,8 +313,8 @@ open class MenuView: UIScrollView {
307313 default : return
308314 }
309315
310- let firstMenuView = menuItemViews. first!
311- let lastMenuView = menuItemViews. last!
316+ guard let firstMenuView = menuItemViews. first,
317+ let lastMenuView = menuItemViews. last else { return }
312318
313319 var inset = contentInset
314320 let halfWidth = frame. width / 2
You can’t perform that action at this time.
0 commit comments