我需要在某些地方使用iOS7特定的代码,通常直到现在这还没有引起太大问题。对于第一个 if 语句,我尝试了一些不同的方法,接缝下方的语句是推荐的方法。没有一个有效。我得到的错误是这样的:
dyld: Symbol not found: _UITransitionContextToViewControllerKey
Referenced from: /Users/pese/Library/Application Support/iPhone Simulator/6.1/Applications/0A4B5156-84D8-41DE-C9D1-2E4C9DB38983/aaaa.app/aaaa
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/UIKit.framework/UIKit
in /Users/pese/Library/Application Support/iPhone Simulator/6.1/Applications/0A4B5156-84D8-41DE-C9D1-2E4C9DB38983/aaaa.app/aaaa
Program ended with exit code: 0
和我的代码:
if ( &UITransitionContextToViewControllerKey != nil )
{
id<UIViewControllerTransitionCoordinator> tc = self.topViewController.transitionCoordinator;
[tc animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
CGRect newRect = _inRect;
if ([context viewControllerForKey:UITransitionContextToViewControllerKey] == [self.viewControllers objectAtIndex:0])
{
newRect = _outRect;
}
_backButton.frame = newRect;
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
BOOL enableSwipeToGoBack = YES;
if ([context viewControllerForKey:UITransitionContextToViewControllerKey] == [self.viewControllers objectAtIndex:0] && ![context isCancelled])
{
enableSwipeToGoBack = NO;
}
self.interactivePopGestureRecognizer.enabled = enableSwipeToGoBack;
}];
}
如果我只是在 if 语句中输入 NO,它可以工作,但我想编译器会在编译期间删除代码。如果我用nil
替换两个UITransitionContextToViewControllerKey
,它也可以工作。此外,导致错误的符号在UIKit/UIViewControllerTransitioning.h中定义,如下所示:
UIKIT_EXTERN NSString *const UITransitionContextToViewControllerKey NS_AVAILABLE_IOS(7_0);
任何帮助将不胜感激。
溶液:
使 UIKit 框架可选,并在测试时更改为:
NSString * const *exists = &UITransitionContextToViewControllerKey;
if ( exists != NULL )
....
正如其他人所提到的,测试功能通常更好,但您可以使用编译器指令根据操作系统版本有条件地进行编译。
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
// target is iOS
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 70000
// target is lower than iOS 7.0
NSLog(@"This message should only appear if iOS version is 6.x or lower");
#else
// target is at least iOS 7.0
#endif
#endif