在斯威夫特2在iOS 8.4,我怎样检测时,蓝牙键盘的Up,Down或Space按下按键吧,所以我可以用行动回应?示例代码会很有帮助.
我的应用程序中使用了以下代码来更改textview中text和big和italic之间的状态.我一直试图在Swift中重写它,但我不断收到编译错误.以下是在线教程中提供给我的Objective-C版本.接下来是我的新swift版本,直到该方法崩溃.
我会推荐任何帮助我理解为什么编译器抱怨这么多的帮助.
-(void)addOrRemoveFontTraitWithName:(NSString *)traitName andValue:(uint32_t)traitValue{
NSRange selectedRange = [_field2 selectedRange];
NSDictionary *currentAttributesDict = [_field2.textStorage attributesAtIndex:selectedRange.location
effectiveRange:nil];
UIFont *currentFont = [currentAttributesDict objectForKey:NSFontAttributeName];
UIColor *currentColor = [currentAttributesDict objectForKey:NSForegroundColorAttributeName];
UIColor *currentBGColor = [currentAttributesDict objectForKey:NSBackgroundColorAttributeName];
UIFont *currentUnderlinedText = [currentAttributesDict objectForKey:NSUnderlineStyleAttributeName];
NSMutableParagraphStyle *currentparagraphStyle = [currentAttributesDict objectForKey:NSParagraphStyleAttributeName]; //receive and set new font name
UIFontDescriptor *fontDescriptor = [currentFont fontDescriptor];
NSString *fontNameAttribute = [[fontDescriptor fontAttributes] objectForKey:UIFontDescriptorNameAttribute];
UIFontDescriptor *changedFontDescriptor;
if ([fontNameAttribute rangeOfString:traitName].location == NSNotFound) {
uint32_t existingTraitsWithNewTrait = [fontDescriptor symbolicTraits] | traitValue;
changedFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:existingTraitsWithNewTrait];
}
else{
uint32_t …Run Code Online (Sandbox Code Playgroud)