请有人帮忙排序一个菜鸟吗?我已经在各种论坛上发布了这个问题并且没有得到任何答案,而许多搜索其他答案已经发现了stackOverflow,所以我希望这就是这个地方.
我有一个BeachView.h(UIScrollView的子类,沙滩的图片),随机数量为Stone.h(UIImageView的子类,一个石头的随机PNG,userInteractionEnabled = YES接受触摸).
如果用户触摸并在海滩上移动,则应滚动.如果用户点击一块石头,它应该调用方法"touchingStone".如果用户点击没有石头的海滩,则应调用方法"touchingBeach".
现在,我意识到这听起来很简单.每个人和每件事都告诉我,如果UIScrollView上有某些东西接受它应该将控制传递给它的触摸.所以当我触摸并拖动时,它应该滚动; 但如果我点击它,它在石头上,它应该忽略海滩水龙头并接受石头水龙头,是吗?
但是,似乎两个视图都接受了水龙头并且同时调用了触摸的石头和触摸的海滩.此外,沙滩水龙头首先发生,所以我甚至不能放入"如果触摸石头然后不运行touchBeach"类型的标志.
这是一些代码.在BeachView.m上
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (self.decelerating) { didScroll = YES; }
else { didScroll = NO; }
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:touch.view];
NSLog(@"touched beach = %@", [touch view]);
lastTouch = touchLocation;
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
didScroll = YES;
[super touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (didScroll == NO && isPaused == NO) {
[self touchedBeach:YES …Run Code Online (Sandbox Code Playgroud) 我有一个接收许多不同类型对象的方法,并决定如何处理它们:
-(void)performAction:(NSObject *)myAction withItem:(Item *)myItem {
actionCount = -1;
NSLog(@"-- NEW ACTION ARRAY --");
if ([myAction isMemberOfClass:[Look class]]) {
currentActionArray = [self createLookArray:(Look *)myAction item:myItem];
} else if ([myAction isMemberOfClass:[Use class]]) {
currentActionArray = [self createUseArray:(Use *)myAction item:myItem];
} else if ([myAction isMemberOfClass:[Exit class]]) {
currentActionArray = [self createExitArray:(Exit *)myAction item:myItem];
} else if ([myAction isMemberOfClass:[NSArray class]] ) {
NSLog(@"--- CUSTOM ACTION --- %@", myAction);
currentActionArray = (NSArray *)myAction;
}
[self performNextAction];
Run Code Online (Sandbox Code Playgroud)
}
这里有四件事之一:Look,Use,Exit或NSArray.前三个被送去成为NSArrays,最后一个已经是NSArray.
现在,当我从其他地方传递NSArray时,就像这样:
NSArray *myAction = [[NSArray alloc] …Run Code Online (Sandbox Code Playgroud)