[英]iOS7 specific code in iOS6
我需要在某些地方使用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,那么它可以工作,但是我猜编译器会在编译过程中删除代码。 如果我将两个UITransitionContextToViewControllerKey
替换为nil
它也可以工作。 此外,在UIKit / UIViewControllerTransitioning.h中定义了导致错误的符号,如下所示:
UIKIT_EXTERN NSString *const UITransitionContextToViewControllerKey NS_AVAILABLE_IOS(7_0);
任何帮助将不胜感激。
解:
使UIKit框架为可选,并更改测试范围:
NSString * const *exists = &UITransitionContextToViewControllerKey;
if ( exists != NULL )
....
正如其他人提到的那样,测试功能通常会更好,但是您可以使用编译器指令根据OS版本有条件地进行编译。
#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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.