Skip to content

Commit

Permalink
fix iOS 8
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlui committed Sep 27, 2016
1 parent ec45e4b commit 0d7fa09
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions SwiftNotice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SwiftNotice: NSObject {
static var timer: DispatchSource!
static var timerTimes = 0

/* iOS 10 fix the orientation bug finally.
/* just for iOS 8
*/
static var degree: Double {
get {
Expand Down Expand Up @@ -104,6 +104,21 @@ class SwiftNotice: NSObject {
window.frame = frame
view.frame = frame

if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
var array = [UIScreen.main.bounds.width, UIScreen.main.bounds.height]
array = array.sorted(by: <)
let screenWidth = array[0]
let screenHeight = array[1]
let x = [0, screenWidth/2, screenWidth/2, 10, screenWidth-10][UIApplication.shared.statusBarOrientation.hashValue] as CGFloat
let y = [0, 10, screenHeight-10, screenHeight/2, screenHeight/2][UIApplication.shared.statusBarOrientation.hashValue] as CGFloat
window.center = CGPoint(x: x, y: y)

// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * M_PI / 180))
}

window.windowLevel = UIWindowLevelStatusBar
window.isHidden = false
window.addSubview(view)
Expand Down Expand Up @@ -146,9 +161,17 @@ class SwiftNotice: NSObject {

window.frame = frame
mainView.frame = frame
window.center = rv!.center

if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * M_PI / 180))
}

window.windowLevel = UIWindowLevelAlert
window.center = rv!.center
window.isHidden = false
window.addSubview(mainView)
windows.append(window)
Expand All @@ -174,9 +197,17 @@ class SwiftNotice: NSObject {
mainView.frame = superFrame

label.center = mainView.center
window.center = rv!.center

if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * M_PI / 180))
}

window.windowLevel = UIWindowLevelAlert
window.center = rv!.center
window.isHidden = false
window.addSubview(mainView)
windows.append(window)
Expand Down Expand Up @@ -212,6 +243,15 @@ class SwiftNotice: NSObject {

window.frame = frame
mainView.frame = frame
window.center = rv!.center

if let version = Double(UIDevice.current.systemVersion),
version < 9.0 {
// change center
window.center = getRealCenter()
// change direction
window.transform = CGAffineTransform(rotationAngle: CGFloat(degree * M_PI / 180))
}

window.windowLevel = UIWindowLevelAlert
window.center = rv!.center
Expand All @@ -236,16 +276,14 @@ class SwiftNotice: NSObject {
}
}

/* iOS 10 Deprecated
// fix orientation problem
// just for iOS 8
static func getRealCenter() -> CGPoint {
if UIApplication.shared.statusBarOrientation.hashValue >= 3 {
return CGPoint(x: rv!.center.y, y: rv!.center.x)
} else {
return rv!.center
}
}
*/
}

class SwiftNoticeSDK {
Expand Down
Binary file not shown.

0 comments on commit 0d7fa09

Please sign in to comment.