我有一個繪圖模擬SKScene,在iOS 8中無法正常工作,這在iOS 8中不起作用。這既適用於模擬器,也適用於設備。SpriteKit在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找到的代碼寫入。