触摸移动在CAShapeLayer绘图慢/ laggy

正如在先前的StackOverflow问题中向我推荐的那样,我试图改进我的绘图方法,让我的用户在UIView中绘制线条/点。 我现在试图绘制使用CAShapeLayer而不是dispatch_async。 然而,这一切都正常工作,但是,在触摸移动的同时不断移动到CAShapeLayer中变得缓慢,path滞后,而我的旧的(效率低下的我被告知)代码工作得非常stream畅和快速。 你可以看到我的旧代码注释如下。 有什么办法来改善我想要做的事情吗? 也许我正在过度看待一些事情。 我会很感激提供的任何帮助。 码: @property (nonatomic, assign) NSInteger center; @property (nonatomic, strong) CAShapeLayer *drawLayer; @property (nonatomic, strong) UIBezierPath *drawPath; @property (nonatomic, strong) UIView *drawView; @property (nonatomic, strong) UIImageView *drawingImageView; CGPoint points[4]; – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; self.center = 0; points[0] = [touch locationInView:self.drawView]; if (!self.drawLayer) […]

Sprite Kit – 使用Impulse在angular色上射击弹丸

我正在开发一个使用Sprite-Kit(Objective-C)的游戏。 这是一个游戏,你在飞行中控制一只鸟,从屏幕的右侧/上侧/下侧向你射击箭头和其他不良射弹。 我使用物理学而不是SKAction来完成这个任务,因为我希望它看起来像生命一样可能。 所以我知道用射弹上的applyImpulse把它射向小鸟,但是我想知道的是怎样才能保证射弹直接射到小鸟身上,不pipe鸟的y坐标和y坐标弹丸之前应用脉冲? 我有一个非常令人沮丧的时间完成这个,所以任何帮助这个问题将不胜感激。 谢谢。

自定义UITableViewCell with reuseIdentifier没有样式?

在我的tableview中,我需要一堆(5-6种)不同的单元格。 所有项目都具有相同的视觉布局,但内容明智(标签名称,图片和颜色),它们有很大的不同。 所以我有一个CustomUITableViewCell基类,在Interface Builder中用这个通用devise来devise。 这个CustomUITableViewCell类服务器作为一组单元子类的基类。 我使用工厂模式从工厂类的类方法生成这些子类。 这些子类没有xibs。 他们为什么会有共同的devise。 现在问题是,对于每个子类我需要一个不同的重用标识符。因此,人们会认为让我们覆盖每个子类的默认初始化器,并在其中调用另一个初始化器, initWithStyle:reuseIdentifier: 问题是它需要风格来指定。 它抱怨说,我不能把nil 。 但是我不需要苹果的任何风格,我明显有自己的风格,如果我想要有一个股票风格,为什么要做定制devise? 我只需要指定reuseIdentifier。 如果它是只读属性,如何分配重用标识符,似乎是通过初始化程序提供它的唯一方法?

iOS7:后台任务(“myapp”具有超出允许时间的有效断言)

崩溃报告细节: Hardware Model: iPhone5,2 Exception Type: 00000020 Exception Codes: 0x000000008badf00d Highlighted Thread: 3 Application Specific Information: MyApp[1369] has active assertions beyond permitted time: {( <BKProcessAssertion: 0x175ca7d0> identifier: Called by MyApp, from -[AppDelegate applicationDidEnterBackground:] process: MyApp[1369] permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:1369 preventSuspend preventIdleSleep preventSuspendOnSleep )} 线程3: Thread 3 name: com.apple.NSURLConnectionLoader Thread 3: 0 libsystem_kernel.dylib 0x3937ea50 […]

Swift Retreive Firebase数据

Firebase数据库中的以下数据: { "schedule": { "Week 1": { "active": "true" }, "Week 2": { "active": "true" }, "Week 3": { "active": "false" }, "Week 4": { "active": "true" }, … } } 我想检索所有的活动只是真正的周。 我正在设置Firebase参考: ref = FIRDatabase.database().reference(withPath: "Schedule") 然后执行以下操作: ref.observeSingleEvent(of: .value, with: { snapshot in // print("Count: ", snapshot.childrenCount) for _ in snapshot.children { print("\(snapshot.value)") } […]

CoreData:使用NSDictionaryResultType提取多对多关系的计数

核心数据中有大量的对象(大约5万个,并且定期增加)。 我用下面的请求来获取它: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:[SongObject name]]; fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]; fetchRequest.propertiesToFetch = @[@"uid", @"name", @"toArtistRef.uid", @"toArtistRef.name"]; fetchRequest.resultType = NSDictionaryResultType; 实体SongObject也包含与toSongsInPlaylistRef关系,这是toSongsInPlaylistRef -many。 我需要为每个对象提取这个集合的数量。 由于大量的数据,我无法取得关系本身。 我尝试添加@"toSongsInPlaylistRef.@count"和@"toSongsInPlaylistRef.count"但它崩溃 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid to many relationship in setPropertiesToFetch: (toSongsInPlaylistRef.count)' 请写下任何build议。

无法使用AVCapturePhotoOutput捕捉照片swift + xcode

我正在一个自定义相机应用程序和教程使用AVCaptureStillImageOutput,这是不赞成ios 10.我已经设置了相机,我现在卡在如何拍照 这里是我充分的看法,我有相机 import UIKit import AVFoundation var cameraPos = "back" class View3: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { @IBOutlet weak var clickButton: UIButton! @IBOutlet var cameraView: UIView! var session: AVCaptureSession? var stillImageOutput: AVCapturePhotoOutput? var videoPreviewLayer: AVCaptureVideoPreviewLayer? override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) clickButton.center.x = cameraView.bounds.width/2 […]

AFNetworking嵌套json中的post image

我必须发送一个嵌套的json请求,其中包括一个内部层次结构的图像。 例如: {"product" : { "catalogue_id" : "x", "name" : "my product", "image" : #<image> } } 问题是如果我尝试使用multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:和appendPartWithFileData:name:fileName:mimeType: ,传入catalogue_id和名称为参数,图像字段后面添加“产品”,如下所示: {"product" : { "catalogue_id" : "x", "name" : "my product" } , "image" : #<image> } 有没有办法指定图像字段嵌套在一定的深度? 感谢堆

静态单元格:内容不出现

我只是想要有一个静态表查看其中的项目。 我使用Xcode 4.2和故事板来完成这个任务。 所以我创build了一个TableViewController(子类UITableViewController)的TableView。 我将内容定义为“静态单元格”和样式“分组”。 在那之后,我把这些单元中的一些标签和所有这些物品都放进去了。 我在tableViewController中创build了Outlets: #import <UIKit/UIKit.h> @interface tableviewcontroller : UITableViewController @property (weak, nonatomic) IBOutlet UILabel *label1; @property (weak, nonatomic) IBOutlet UILabel *label2; @property (weak, nonatomic) IBOutlet UISegmentedControl *segmented; @property (weak, nonatomic) IBOutlet UIImageView *imageview; @property (weak, nonatomic) IBOutlet UITextView *text; @end 把一些内容放在cell-label中: – (void)viewDidLoad { [super viewDidLoad]; self.label1.text = @"This is a […]

在iOS上,如何使cell.imageView刷新其内容?

我在tableView:cellForRowAtIndexPath尝试通过调用设置图像 [self downloadImage:urlString andSetIntoCellImageView:cell] 在downloadImage ,它将调用NSURLConnection:sendAsynchronousRequest (仅适用于iOS 5及更高版本),并在完成块中通过使用设置图像 cell.imageView.image = [UIImage imageWithData:data]; // data is downloaded data 它工作,如果在tableView:cellForRowAtIndexPath , imageView填充一个虚拟的占位符图像 – 我不知道如何刷新新的图像,是由setNeedsDisplay做一个重绘? 但是,如果我不设置占位符图像,那么新的图像将不会显示。 我不知道可以使用什么机制来显示图像? 如果我使用 [cell.imageView setNeedsDisplay] 要么 [cell setNeedsDisplay]; 在完成块,它将无法正常工作,如果我使用 [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 通过使downloadImage接受indexPath完成块,它将再次调用tableView:cellForRowAtIndexPath ,并导致无限循环。 所以好像我需要使用一些哈希表来记住图像是否已经在哈希表中:如果没有,调用downloadImage ,如果在哈希表中,只需使用它,所以不会有无限循环。 但有没有一种简单的方法来使图像显示出来? 设置一个占位符图像的作品,但如果我们不 – 通过什么机制的占位符导致图像刷新?