如何检查字体是否受字体支持

我正在与一个文本字段的应用程序工作。 在这个字段中写的文字将会被打印出来,而且我还有一些像表情符号,中文字符等字符的问题,因为字体不提供这些字符。 这就是为什么我想要得到字体提供的所有字符(字体被下载,所以我可以直接处理文件或与UIFont对象)。 我听说过CTFontGetGlyphsForCharacters但我不确定这个函数做我想要的,我不能得到它的工作。 这是我的代码: CTFontRef fontRef = CTFontCreateWithName((CFStringRef)font.fontName, font.pointSize, NULL); NSString *characters = @"🐯"; // emoji character NSUInteger count = characters.length; CGGlyph glyphs[count]; if (CTFontGetGlyphsForCharacters(fontRef, (const unichar*)[characters cStringUsingEncoding:NSUTF8StringEncoding], glyphs, count) == false) NSLog(@"CTFontGetGlyphsForCharacters failed."); 这里CTFontGetGlyphsForCharacters返回false 。 这是我想要的,因为字符“🐯”不是由所使用的字体提供的。 问题是当我用NSString *characters = @"🐯"replaceNSString *characters = @"🐯" NSString *characters = @"abc" , CTFontGetGlyphsForCharacters再次返回false 。 显然,我的字体为所有的ASCII字符提供了一个字形。

已弃用GKMatchMaker邀请处理程序

我有我以前用来处理邀请的以下代码: [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) { // Insert game-specific code here to clean up any game in progress. if (acceptedInvite) { GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite]; mmvc.matchmakerDelegate = self; [self presentViewController:mmvc animated:YES completion:nil]; } }; 但是,现在已经在iOS 7被弃用了。 在哪里以及如何在我的项目中注册GameKit邀请处理程序?

用不同的types重新定义

我在这段代码中遇到了问题: for (int i = 0; i < [tempInviteeArray count]; i++) { NSArray *tempContact = [tempInviteeArray objectAtIndex:i]; NSDictionary *tempContactDictionary = [tempContact objectAtIndex:1]; int tempContactDelay = [[tempContact objectAtIndex:2] intValue]; FlokContact *tempContact = [[FlokContact alloc] initWithJSONData:tempContactDictionary andDelay:tempContactDelay]; } 最后一行抛出一个错误: "Redefinition of 'tempContact' with a different type initWithJSONData:接受NSDictionary和延迟:int 我试图重写这个代码,不同的types和所有,我只是不知道我在做什么

确定哪一个UIImageView显示的animationImages?

有没有办法找出它的animationUIImage是哪一帧? 当你启动它时,你给它一个animationImages数组,所以显然必须存储当前图像的索引。 你知道我怎么能find这个? 另外,有没有办法告诉UIImageView哪个框架开始animation?

如何区分用户是否用手指或苹果铅笔拍屏幕?

该应用程序支持iPad Pro,它必须使用Apple Pencil。 我想要做的是区分用户是否使用苹果铅笔或他的手指。 就像是: if( the user is pressing the screen with his finger){ do something } else if ( the user is pressing the screen with an Apple Pencil){ do something else } 我发现UITouchTypeStylus属性,但无法知道它是如何工作的。 我的主要问题是,这里只有很less的例子,它们是用快速编写的,但是我的工作是客观的,而且我不能真正理解这些例子。 看看这个,我从苹果开发者那里find一个样本,这是一个函数: func addPointsOfType(var type: LinePoint.PointType, forTouches touches: [UITouch], toLine line: Line, currentUpdateRect updateRect: CGRect) -> CGRect { var […]

iOS的MapKit拖动注解(MKAnnotationView)不再与地图平移

我正在学习在我刚刚起步的iOS应用程序中使用MapKit。 我正在使用一些模型实体作为注释(将<MKAnnotation>协议添加到它们的头文件中)。 我也创build自定义MKAnnotationViews并将draggable属性设置为YES 。 我的模型对象有一个location属性,它是一个CLLocation* 。 为了符合<MKAnnotation>协议,我向该对象添加了以下内容: – (CLLocationCoordinate2D) coordinate { return self.location.coordinate; } – (void) setCoordinate:(CLLocationCoordinate2D)newCoordinate { CLLocation* newLocation = [[CLLocation alloc] initWithCoordinate: newCoordinate altitude: self.location.altitude horizontalAccuracy: self.location.horizontalAccuracy verticalAccuracy: self.location.verticalAccuracy timestamp: nil]; self.location = newLocation; } – (NSString*) title { return self.name; } – (NSString*) subtitle { return self.serialID; } 所以,我有4个必要的方法。 而且他们非常简单。 当我阅读MKAnnotationView和@draggable属性中的苹果文档时,它说: 将该属性设置为YES可使用户拖放注释。 […]

为NSAttributedString的不同部分应用不同的属性

我知道可以将属性应用于NSAttributedString。 但是,我们如何将不同的属性应用于相同的属性string 为string“这是一个归因文本”。 我们如何设置一个特定的属性(背景颜色或前景色)为“这是”另一个属性(背景色或前景色)为“属性文本”。 有什么办法来实现这个….? 还有什么办法可以在iOS中设置NSAttributedString的背景颜色?

如何从ALAssetRepresentation获取正确的旋转UIImage?

我正在尝试使用fullScreenImage方法从ALAssetRepresentation获取正确旋转的UIImage 。 我有几个testing照片在各种设备方向拍摄; 照片在照片应用中正确显示。 fullScreenImage的文档说: 在iOS 5和更高版本中,此方法返回完全裁剪,旋转和调整的图像 – 完全像用户在照片或图像select器中看到的一样。 要从CGImage创build一个正确旋转的UIImage对象,可以使用imageWithCGImage:scale:orientation:或initWithCGImage:scale:orientation:传递orientation和scale值。 鉴于文档,我的代码如下所示: ALAssetRepresentation *rep = [asset defaultRepresentation]; UIImage *img = [UIImage imageWithCGImage:[rep fullScreenImage] scale:[rep scale] orientation:[rep orientation]]; 但是由此产生的UIImage的旋转是错误的。 当我用UIImageOrientationUpreplace[rep orientation]时,对于所有的testing照片,图像都是正确的。 显然,我很犹豫要坚持这个“解决scheme”,因为它感觉像一个黑客。 我究竟做错了什么?

比较两张图片是否相同(iOS)

可能重复: 在iPhone上,如何将一个图像与另一个图像进行比较以查看它们是否相似? 我发现这个代码,并试图更好地理解它: UIImage *img1 = // Some photo; UIImage *img2 = // Some photo; NSData *imgdata1 = UIImagePNGRepresentation(img1); NSData *imgdata2 = UIImagePNGRepresentation(img2); if ([imgdata1 isEqualToData:imgdata2]) { NSLog(@"Same Image"); } 这将确认图像1是否与图像2完全相同? 这种方法是否是最佳实践,还是有更好的方法呢?

在后台线程从HTML的NSAttributedString

我需要的是从相对较大的HTMLstring创buildNSAttributedString对象,并将它们(NSAttributedString-s)存储在数据库中。 当然,我想在后台线程中这样做。 这里是一个简单的代码(失败)来演示我正在尝试做什么: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *HTMLString = @"<p>HTML string</p>"; NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding)}; NSError *error = nil; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithData:[HTMLString dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:&error]; }); 根据这个讨论 ,根本不可能在后台线程中执行它,因为使用NSHTMLTextDocumentType选项创buildNSHTMLTextDocumentType选项使用WebKit ,它需要在执行任何asynchronous工作时旋转runloop。 但可能是别人想通了? 我有非常简单的HTML,只是文本和链接,可能有一种方法来指定,从HTML创build一个NSAttributedString不会需要任何“ WebKit -rendering”? 或者可能有人可以推荐第三方库从简单的HTML不使用WebKit创buildNSAttributedString ?