Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
忽略iOS:Accessibility中的动态类型_Ios_Iphone_Ios8_Accessibility - Fatal编程技术网

忽略iOS:Accessibility中的动态类型

忽略iOS:Accessibility中的动态类型,ios,iphone,ios8,accessibility,Ios,Iphone,Ios8,Accessibility,有没有办法完全忽略iOS应用程序中的动态类型/字体大小设置? 我的意思是,有没有一种像plist条目这样的方法,我可以完全禁用它。我知道有一个通知,我们可以观察和重新配置字体时,有变化的设置。我正在寻找一个更简单的解决方案。我正在使用iOS8。 谢谢。在应用程序中添加: swift相当于@means matters的答案如下: 在AppDelegate中: @objc func swizzled_preferredContentSizeCategory() -> UIContentSize

有没有办法完全忽略iOS应用程序中的动态类型/字体大小设置? 我的意思是,有没有一种像plist条目这样的方法,我可以完全禁用它。我知道有一个通知,我们可以观察和重新配置字体时,有变化的设置。我正在寻找一个更简单的解决方案。我正在使用iOS8。 谢谢。

在应用程序中添加:


swift相当于@means matters的答案如下:

在AppDelegate中:

@objc func swizzled_preferredContentSizeCategory() -> UIContentSizeCategory {
    return UIContentSizeCategory.small
}

open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let originalMethod = class_getInstanceMethod(UIApplication.self, #selector(preferredContentSizeCategory))
    let swizzledMethod = class_getInstanceMethod(UIApplication.self, #selector(swizzled_preferredContentSizeCategory))
    method_exchangeImplementations(originalMethod, swizzled_preferredContentSizeCategory)
}

只需提供Swift 4解决方案即可。 Objective-C中的preferredContentSizeCategory是一个方法,但在Swift中它是一个只读变量。因此,在您的AppDelegate中如下所示:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    // MARK: - UIApplicationDelegate

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        UIApplication.classInit

        self.window = UIWindow(frame: UIScreen.main.bounds)
        ...
        self.window?.makeKeyAndVisible()
        return true
    }
}

// MARK: - Fix Dynamic Type

extension UIApplication {

    static let classInit: Void = {
        method_exchangeImplementations(
            class_getInstanceMethod(UIApplication.self, #selector(getter: fixedPreferredContentSizeCategory))!,
            class_getInstanceMethod(UIApplication.self, #selector(getter: preferredContentSizeCategory))!
        )
    }()

    @objc
    var fixedPreferredContentSizeCategory: UIContentSizeCategory {
        return .large
    }
}

没有必要关闭应用程序。只需将UIApplication子类化,并提供您自己的preferredContentSizeCategory实现:

斯威夫特:

class MyApplication: UIApplication {

    override var preferredContentSizeCategory: UIContentSizeCategory {
        get { return UIContentSizeCategory.large }
    }
}

UIApplicationMain(
    CommandLine.argc,
    CommandLine.unsafeArgv,
    NSStringFromClass(MyApplication.self),
    NSStringFromClass(AppDelegate.self)
)
目标C:

@interface MyApplication : UIApplication
@end

@implementation MyApplication

- (UIContentSizeCategory) preferredContentSizeCategory
{
    return UIContentSizeCategoryLarge;
}

@end

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([MyApplication class]), NSStringFromClass([AppDelegate class]));
    }
}

动态类型是您必须在Interface Builder中积极实现或至少选择的内容。它不仅仅起作用。如果我在手机的设置应用程序中更改字体大小,然后返回到我的应用程序,字体就会改变。我没有为此做任何事情。你在界面生成器中使用什么字体?没有使用界面生成器/情节提要。已将代码中的字体设置为某个浮点值。@Fabiopoli是,如果您使用默认的UITableViewCell,它将自动工作labels@zeeple应该是可能的。我只在Obj-C中有它。我试图快速转换为Swift 2.2,但这需要整理各种典型的Swift选择器和类型相关问题;我现在没有时间做那件事。请用您的Swift版本发布答案。此解决方案仅在启动应用程序时有效。如果用户碰巧修改了字体大小并立即恢复应用程序,此解决方案将不适用于该情况:当我尝试使用它时,会出现编译器错误:使用未解析的标识符“preferredContentSizeCategory”。是否还需要其他一些东西才能使其工作?我的最佳猜测是将选择器更改为getter:UIApplication.preferredContentSizeCategory和MyAppDelegate.swizzled_preferredContentSizeCategory以及其他一些更改,这些更改清除了编译器错误,但在运行时似乎没有任何作用。适用于iOS 11。在实现此功能的过程中,我了解到我一直在iPhone上进行所有的开发工作,将较大的文本滑块设置为UIContentSizeCategory,比默认值大一个。除非使用新的模拟器,否则无法知道设置中的默认值或重置为默认值。即使关闭,较大的文本滑块也始终处于活动状态。当开关打开时,滑块的范围更大。短而甜。在iOS 13中为我工作。
@interface MyApplication : UIApplication
@end

@implementation MyApplication

- (UIContentSizeCategory) preferredContentSizeCategory
{
    return UIContentSizeCategoryLarge;
}

@end

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([MyApplication class]), NSStringFromClass([AppDelegate class]));
    }
}