gpt4 book ai didi

ios - 停止 MCBrowserViewController 旋转。忽略 plist 并且不会子类化

转载 作者:行者123 更新时间:2023-11-29 11:37:06 28 4
gpt4 key购买 nike

我希望多人连接点选择器 View 像应用中的其他所有内容一样启动并保持横向。

plist 有“Supported interface orientations”,仅包含“landscape(右主页按钮)”,但 MCBrowserViewController 忽略它。

我试图子类化以override supportedInterfaceOrientations,但根据这个link ,它不支持这个。 presentViewController,适用于 MCBrowserViewController,提供:

uncaughtExceptionHandler; NSInternalInconsistencyException: Could not load NIB in bundle:
'NSBundle </var/containers/Bundle/Application/B2B62F00-15A1-4063-89B0-52EB7F3E464C/
Parsec.app> (loaded)' with name 'MCBrowserViewController'

感谢您的帮助。

最佳答案

我编写了一个非常基本的示例应用程序并使用 iOS 11.2 对其进行了测试。对我来说,似乎 MCBrowserViewController 遵守应用程序级别的方向限制。

您应该通过提供 application(_:supportedInterfaceOrientationsFor:) 的实现来检查您的应用程序委托(delegate)是否未覆盖 plist 方向值.或者,如果您有 UIApplication 的自定义子类,请确保它没有覆盖 supportedInterfaceOrientations(for:)。 .

我在这里包含了完整的源代码:

ViewController.swift:

import UIKit
import MultipeerConnectivity

class ViewController: UIViewController {

var textField: UITextField?
let id = MCPeerID(displayName: "testpeer")
lazy var session = MCSession(peer: id)

override func viewDidLoad() {
super.viewDidLoad()

let button = UIButton(frame: CGRect(x: 100, y: 100, width: 0, height: 0))
button.setTitle("Browse", for: .normal)
button.backgroundColor = .red
button.addTarget(self, action: #selector(showBrowser), for: .touchUpInside)
button.sizeToFit()
view.addSubview(button)
}

@objc func showBrowser() {
let controller = MCBrowserViewController(serviceType: "test", session: session)
present(controller, animated: true)
controller.delegate = self
}
}

extension ViewController: MCBrowserViewControllerDelegate {

func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) {
self.presentedViewController?.dismiss(animated: true)
}

func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) {
self.presentedViewController?.dismiss(animated: true)
}
}

AppDelegate.swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

return true
}
}

信息.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

关于ios - 停止 MCBrowserViewController 旋转。忽略 plist 并且不会子类化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538842/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com