我想我在 UIDevice.orientation 变量中发现了一个错误。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
if UIDevice.current.orientation.isPortrait{
print("Orientation is Portrait")
}
else{
print("Orientation is Landscape")
}
}
Run Code Online (Sandbox Code Playgroud)
如果我将设备(Iphone 5)握在手中,一切正常,但如果它平放在桌子上,即使一切都以纵向显示并且设备本身没有旋转,我也会得到“方向是风景”。有什么可能的方法来反对这个吗?
// 编辑:此测试在按钮操作中也失败。
我在应用程序中使用的正则表达式是用户输入和代码的组合。因为我不想限制用户,所以我想从条目中转义所有与正则表达式相关的字符,如“+”、方括号、斜线等。是否有一个函数或至少一种简单的方法来获取数组中的所有这些字符,以便我可以执行以下操作:
for regexChar in regexCharacterArray{
myCombinedRegex = myCombinedRegex.replaceOccurences(of: regexChar, with: "\\" + regexChar)
}
Run Code Online (Sandbox Code Playgroud)