我创建了一个自定义Toast消息,并将此消息添加到自定义DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
String query = "insert into DATA(SERIAL,BLADETYPE,STARTT1) values (?, ?, ?)";
try (PreparedStatement pstmt = conn.prepateStatement(query)) {
pstmt.setString(1, bladeSerial);
pstmt.setString(2, bladeType);
pstmt.setString(3, startTime1.format(formatter));
pstmt.executeUpdate();
} catch (SQLException e) {
// Exception handling
}
(因为我希望此消息在所有内容之上)。
我的自定义toast消息只不过是UIWindow
的{{1}}和UIViewController
的子类,我添加了UIView
这是吐司消息。
就自定义UIViewController
而言,我从UILabel
中取出了这个类,这就是它的样子......
UIWindow
我知道, iOS 8 中的JLToast
有一些实施更改,所以如果我向public class JLToastWindow: UIWindow {
public static let sharedWindow = JLToastWindow(frame: UIScreen.mainScreen().bounds)
/// Will not return `rootViewController` while this value is `true`. Or the rotation will be fucked in iOS 9.
var isStatusBarOrientationChanging = false
var shouldRotateManually: Bool {
let iPad = UIDevice.currentDevice().userInterfaceIdiom == .Pad
let application = UIApplication.sharedApplication()
let window = application.delegate?.window ?? nil
let supportsAllOrientations = application.supportedInterfaceOrientationsForWindow(window) == .All
let info = NSBundle.mainBundle().infoDictionary
let requiresFullScreen = info?["UIRequiresFullScreen"]?.boolValue == true
let hasLaunchStoryboard = info?["UILaunchStoryboardName"] != nil
if #available(iOS 9, *), iPad && supportsAllOrientations && !requiresFullScreen && hasLaunchStoryboard {
return false
}
return true
}
override public var rootViewController: UIViewController? {
get {
guard !self.isStatusBarOrientationChanging else { return nil }
return UIApplication.sharedApplication().windows.first?.rootViewController
}
set { /* Do nothing */ }
}
public override init(frame: CGRect) {
super.init(frame: frame)
self.userInteractionEnabled = false
self.windowLevel = CGFloat.max
self.backgroundColor = .clearColor()
self.hidden = false
self.handleRotate(UIApplication.sharedApplication().statusBarOrientation)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.bringWindowToTop),
name: UIWindowDidBecomeVisibleNotification,
object: nil
)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.statusBarOrientationWillChange),
name: UIApplicationWillChangeStatusBarOrientationNotification,
object: nil
)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.statusBarOrientationDidChange),
name: UIApplicationDidChangeStatusBarOrientationNotification,
object: nil
)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.applicationDidBecomeActive),
name: UIApplicationDidBecomeActiveNotification,
object: nil
)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/// Bring JLToastWindow to top when another window is being shown.
func bringWindowToTop(notification: NSNotification) {
if !(notification.object is JLToastWindow) {
self.dynamicType.sharedWindow.hidden = true
self.dynamicType.sharedWindow.hidden = false
}
}
dynamic func statusBarOrientationWillChange() {
self.isStatusBarOrientationChanging = true
}
dynamic func statusBarOrientationDidChange() {
let orientation = UIApplication.sharedApplication().statusBarOrientation
self.handleRotate(orientation)
self.isStatusBarOrientationChanging = false
}
func applicationDidBecomeActive() {
let orientation = UIApplication.sharedApplication().statusBarOrientation
self.handleRotate(orientation)
}
func handleRotate(orientation: UIInterfaceOrientation) {
let angle = self.angleForOrientation(orientation)
if self.shouldRotateManually {
self.transform = CGAffineTransformMakeRotation(CGFloat(angle))
}
if let window = UIApplication.sharedApplication().windows.first {
if orientation.isPortrait || !self.shouldRotateManually {
self.frame.size.width = window.bounds.size.width
self.frame.size.height = window.bounds.size.height
} else {
self.frame.size.width = window.bounds.size.height
self.frame.size.height = window.bounds.size.width
}
}
self.frame.origin = .zero
dispatch_async(dispatch_get_main_queue()) {
JLToastCenter.defaultCenter().currentToast?.view.updateView()
}
}
func angleForOrientation(orientation: UIInterfaceOrientation) -> Double {
switch orientation {
case .LandscapeLeft: return -M_PI_2
case .LandscapeRight: return M_PI_2
case .PortraitUpsideDown: return M_PI
default: return 0
}
}
}
添加一些视图(这是我正在做的,添加吐司邮件视图自定义UIWindow
以上),然后UIWindow
将不会收到任何轮换更改。由于JLToast好友,这个问题由上面的窗口处理。
我的Toast消息在几乎所有设备中都运行良好,但问题在于 iPad mini 9.3.1和iPad 3 8.3 (在其他设备和版本中,这样可以正常工作) UIWindow / UIView 当使用UIWindow
启动应用或将设备移至UIView/UIWindow
时,强>不旋转。 有趣的是,吐司在iPad mini 9.2上显示正常,但在iPad mini 9.3.1上没有显示 。
任何人都可以为此问题提供一些指针。
编辑:请查看演示Code Here 正如我已经提到过的,这个问题可以在我发现的iPad Mini iOS 9.3.1(非Retina)和iPad 3 iOS8.3上找到。