0
我需要在某些地方使用iOS7特定的代碼,通常這直到現在還沒有引起太多問題。我爲第一條if語句嘗試了一些不同的方法,接下來的方法是推薦的方法。沒有用。我得到的錯誤是這樣的:iOS7中的iOS7特定代碼
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;
}];
}
如果我只是把NO在它工作的if語句,但我想,編譯器在編譯過程中刪除代碼。如果我用nil
替換這兩個UITransitionContextToViewControllerKey
它也可以。也導致錯誤的符號的UIKit/UIViewControllerTransitioning.h定義,並期待這樣的:
UIKIT_EXTERN NSString *const UITransitionContextToViewControllerKey NS_AVAILABLE_IOS(7_0);
任何幫助將不勝感激。
SOLUTION:
製作UIKit框架可選的改變,如果測試:
NSString * const *exists = &UITransitionContextToViewControllerKey;
if (exists != NULL)
....
您需要做一個運行時測試,看看該方法是否存在。您可以測試iOS版本或測試該類是否支持該方法。 –
'UITransitionContextToViewControllerKey!= nil'很好,但你必須添加UIKit作爲一個「可選」框架,我。即使用弱聯動。 – 2014-01-16 14:14:30
@HotLicks如果符號適當地輸出弱符號,那麼OP只需使用正確的鏈接器命令。請注意,OP不使用類的方法,而是使用外部常量。 (另外,我認爲測試功能要比測試操作系統版本更好。) – 2014-01-16 14:15:22