【发布时间】:2014-10-20 17:50:08
【问题描述】:
我有一个绘图模拟 SKScene,它在 iOS 7 中运行良好,但在 iOS 8 中无法运行。这既适用于模拟器,也适用于设备。
场景应该在手指触摸屏幕的地方显示黑线,并且在您完成“绘制”一条线后它们应该持续存在。这是它在 iOS 7 中的屏幕截图:
虽然没有崩溃,但在 iOS 8 中根本不会渲染线条。我只是得到一个空白画布。 NSLogging 表明它确实正确注册了 touchesBegan/Moved/Ended 函数。
我已经完整地制作了整个课程:
@implementation CSDraw
-(id)initWithSize:(CGSize)size type:(NSString *)CSType stresslevel:(NSInteger)stress_indicator { //designated initializer
if (self = [super initWithSize:size type: CSType stresslevel:stress_indicator]) {
NSLog(@"Creating new scene from CSDraw within the init");
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.swiped = NO;
UITouch *touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
self.pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);
self.lineNode = [SKShapeNode node];
self.lineNode.path = self.pathToDraw;
self.lineNode.strokeColor = [SKColor blackColor];
self.lineNode.lineWidth = 10;
self.lineNode.zPosition = 50;
[self addChild:self.lineNode];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
self.swiped = YES;
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
CGPathAddLineToPoint(self.pathToDraw, NULL, positionInScene.x, positionInScene.y);
self.lineNode.path = self.pathToDraw;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
if(!self.swiped) { //user just tapped once, draw a single point
SKSpriteNode *dot = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(10, 10)];
dot.position = positionInScene;
[self addChild: dot];
} else { //calls touchesMoved
}
//[self.lineNode removeFromParent]; //comment out this line if you want line to remain on screen
CGPathRelease(self.pathToDraw);
}
@end
这个类是根据我在this StackOverFlow answer 中找到的代码编写的。
【问题讨论】:
标签: ios8 sprite-kit xcode6