Skip to content
This repository was archived by the owner on Jun 17, 2018. It is now read-only.

Commit 8ae8466

Browse files
committed
Set default width of window or screen
1 parent 8615e8b commit 8ae8466

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Pod/Classes/MenuItemView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

Pod/Classes/MenuView.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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 }

0 commit comments

Comments
 (0)