How does iOS 7 implement the UI elements so that they look different depending on what SDK you compile with?

前端 未结 3 844
醉梦人生
醉梦人生 2021-02-02 00:21

There are elements like UITableViews, UINavigationBars that have a different style on iOS 7.

This style is determined at run time, since those

3条回答
  •  梦如初夏
    2021-02-02 00:46

    My bet is that they use framework compatibility versions.

    Each time you compile your app, your app is linked against an specific framework, with compatibility version and current version. You can see those numbers if you run otool -L YourApp.app/YourApp. For example, for an application compiled some time ago I obtained this:

    /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 751.58.0)
    /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 1500.0.0)
    

    As you can see the full path of the UIKit framework is stored in the Mach-O binary, along a couple of versions (and specially the version I compiled against at that moment).

    I suppose that iOS 7 will have both UIKit version included: the one from iOS6 marked with the corresponding version and saying compatibility from 1.0.0, and the one from iOS7 marked as compatible with something higher than 1500.0.0 (I don’t know if that’s the number for iOS 6.1.3, but you get the idea).

    When your iOS6 binary is loaded, its library dependencies are read by dyld and resolved, because you were compiled saying current version 1500.0.0, and the library for iOS 7 says compatibility version 1501.0.0, you will be linked against the library for iOS 6.

    Since a framework is also a bundle, all the resources are perfectly contained, and will be used only by the right version, and that’s how the different visual elements will look different if you compile against iOS 6 SDK or iOS 7 SDK.

    I might be wrong, but I simply hope they are not using the code technique you propose, because that will be a crappy code base to maintain.

提交回复
热议问题