こんにちは私は私がサブビューとしてのUIViewをロードしていますSpriteKitベースのシーン「メニュー」 (CGScratchViewController.xib)タッチ座標/場所は
-(void)addscratchView:(SKView*)view
{
CGRect viewFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
//ScratchableView : UIView
myScratchView = [[ScratchView alloc]initWithFrame:viewFrame ];
self.name = @"menuScene";
[self.view addSubview:myScratchView];
}
ScratchableViewクラスIに消去することができ層をロードしているすべてを歪め私の指は下の図面を明らかにするオーバーレイ描画
コードは機能しているように見えますが、タッチはオフになっていて、何らかの形で「スケーリング」されているようです。つまり、左上隅に描画すると、 、指を外側にドラッグするとタッチがますます歪みます - 任意の考えこの を修正するために検索する内容に
Scratchableview.h
// Created by Olivier Yiptong on 11-01-11.
//
#import "ScratchableView.h"
@implementation ScratchableView
@synthesize contentScale;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
scratchable = [UIImage imageNamed:@"scratchable.jpg"].CGImage;
width = CGImageGetWidth(scratchable);
height = CGImageGetHeight(scratchable);
self.opaque = NO;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CFMutableDataRef pixels = CFDataCreateMutable(NULL , width * height);
alphaPixels = CGBitmapContextCreate(CFDataGetMutableBytePtr(pixels) , width , height , 8 , width , colorspace , kCGImageAlphaNone);
provider = CGDataProviderCreateWithCFData(pixels);
CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
CGContextFillRect(alphaPixels, frame);
CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(alphaPixels, 20.0);
CGContextSetLineCap(alphaPixels, kCGLineCapRound);
CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
scratched = CGImageCreateWithMask(scratchable, mask);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextDrawImage(UIGraphicsGetCurrentContext() , [self bounds] , scratched);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if([[touch view] isKindOfClass:[UIImageView class]]){
CGPoint point= [touch locationInView:touch.view];
NSLog(@"%f%f",point.x,point.y);
location = point;
}
firstTouch = YES;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
} else {
location = [touch locationInView:self];
previousLocation = [touch previousLocationInView:self];
}
// Render the stroke
[self renderLineFromPoint:previousLocation toPoint:location];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:self];
[self renderLineFromPoint:previousLocation toPoint:location];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end {
CGContextMoveToPoint(alphaPixels, start.x, start.y);
CGContextAddLineToPoint(alphaPixels, end.x, end.y);
CGContextStrokePath(alphaPixels);
[self setNeedsDisplay];
}
- (void)dealloc {
CGContextRelease(alphaPixels);
CGImageRelease(scratchable);
CGDataProviderRelease(provider);
}
とMenuscene
-(void)didMoveToView:(SKView *)view {
self.userInteractionEnabled = YES;
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// [self createButtons ];
[self addscratchView:view]; //for testing
}
-(void)addscratchView:(SKView*)view
{
CGRect viewFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
myScratchView = [[ScratchView alloc]initWithFrame:viewFrame ];
self.name = @"menuScene";
[self.view addSubview:myScratchView];
}
I(初心者作り初心者のミスをしています)座標を変換しようとしました...まだあまり運がありません(多分それは正しいことではありません効果の
//convert between view coordinates and scene coordinates
//coordinate system is not the same in a Sprite Kit scene as they are in a UIView
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchlocation = [touch locationInView:touch.view];
spriteView = (Menu *) spriteView.scene.view;
CGPoint positionInScene = [self convertPoint:touchlocation fromCoordinateSpace:spriteView.scene.view];
ビデオ/歪んタッチ あなたはあなたの考えている方法は、あなたの頭の中でそれらを敷設しているあなたの意見を積層していないように見えますhttps://www.youtube.com/watch?v=dMrcufcKpao
私が最後に何をしたのかは、@ implementation GameViewControllerを削除しています - (void)viewdidload、 - (void)viewWillLayoutSubviews、scene.scaleMode = SKSceneScaleModeAspectFill;これは、システムがviewDidLoadメソッドを呼び出すこの時点で、呼び出し階層にビューが追加されないためです。したがって、ビューのサイズと向きは調整できません(少なくとも私の理解は?) これは問題を修正するようです。ありがとうございました。ドラゴンの騎士は正しい解決策への道に私を置いてくれました! – StackBuddy
ちょっと同じアプローチですが、アスペクトの塗りつぶしがさまざまなデバイスでうまく動作しない場合があります.4秒、5〜6秒(1回のみ必要)、およびiPadでテストします – Knight0fDragon