iOS:目标如何在将手指拖动到一系列图像中的每一个图像上时一次使一张图像发光
目标:当手指在一系列图像中的每一个上拖动时,一次让一个图像发光。
为了自己解决这个问题,我尝试将触摸图像的 Alpha 更新为 1.00,同时将一系列图像中的所有其他图像设置为 Alpha 0.25,因为手指通过 TouchMoved? 在每个单独的图像上拖动?然而我下面的方法没有产生预期的结果。
使用以下模式在 viewDidLoad 中为八个图像中的每一个创建发光叠加图稿:(
-(void)viewDidLoad
{
Glow *imageOne = [[Glow alloc]
initWithNibName:@"ImageOne" bundle:[NSBundle mainBundle]];
self.glowOneView = imageOne;
[imageOne release];
[self.glowOneView setTag:101];
[self.glowOneView setAlpha:0.25];
[self.glowOneView setCenter:CGPointMake(160,135)];
[self.view insertSubview:self.glowOneView atIndex:11];
}
重复上述模式以唯一地创建其余八个图像中的每一个)。
touchesMoved 模式如下所示:(
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Began");
UITouch *touch = [touches anyObject];
if ([touch view] == glowOneView) {
[glowOneView setAlpha:1.00];
[glowTwoView setAlpha:0.25];
[glowThreeView setAlpha:0.25];
[glowFourView setAlpha:0.25];
[glowFiveView setAlpha:0.25];
[glowSixView setAlpha:0.25];
[glowSevenView setAlpha:0.25];
[glowEightView setAlpha:0.25];
NSLog(@"Began Button One");
}
else if ([touch view] == glowTwoView) {
[glowOneView setAlpha:0.25];
[glowTwoView setAlpha:1.00];
[glowThreeView setAlpha:0.25];
[glowFourView setAlpha:0.25];
[glowFiveView setAlpha:0.25];
[glowSixView setAlpha:0.25];
[glowSevenView setAlpha:0.25];
[glowEightView setAlpha:0.25];
NSLog(@"Began Button Two");
}
...
重复上述模式以唯一地处理其余八个图像中的每一个)。
上面的代码片段将使触摸的第一个图像发光,但是当您在视图中拖动时,touchesMoved 不会更新手指拖动的任何后续图像的 Alpha,直到释放触摸并启动新的触摸。
控制台仅显示触摸的第一个图像的touchesMoved NSLog,并且只要拖动手指,就不断重复触摸的第一个图像的NSLog,无论随后拖动的手指下方是哪个图像。
我非常感谢您的建议以及任何替换或更新上述方法的示例,以产生一次使一个图像发光的所需结果,就像将手指拖动到一系列图像中的每一个图像上一样。
谢谢你,
Objective: To get one image at a time to glow, as finger is dragged over each of a series of images.
In an attempt to figure this out on my own, I tried to update the Alpha of the touched image to 1.00 while setting all others in the series of images to alpha 0.25 as finger drags over each individual image via touchesMoved? However my methods below did not produce the desired result.
Artwork for Glow overlay for each of the eight images is created in viewDidLoad using this pattern:
-(void)viewDidLoad
{
Glow *imageOne = [[Glow alloc]
initWithNibName:@"ImageOne" bundle:[NSBundle mainBundle]];
self.glowOneView = imageOne;
[imageOne release];
[self.glowOneView setTag:101];
[self.glowOneView setAlpha:0.25];
[self.glowOneView setCenter:CGPointMake(160,135)];
[self.view insertSubview:self.glowOneView atIndex:11];
}
(repeating the above pattern to uniquely create each of the remaining eight images).
touchesMoved pattern looks like this:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Began");
UITouch *touch = [touches anyObject];
if ([touch view] == glowOneView) {
[glowOneView setAlpha:1.00];
[glowTwoView setAlpha:0.25];
[glowThreeView setAlpha:0.25];
[glowFourView setAlpha:0.25];
[glowFiveView setAlpha:0.25];
[glowSixView setAlpha:0.25];
[glowSevenView setAlpha:0.25];
[glowEightView setAlpha:0.25];
NSLog(@"Began Button One");
}
else if ([touch view] == glowTwoView) {
[glowOneView setAlpha:0.25];
[glowTwoView setAlpha:1.00];
[glowThreeView setAlpha:0.25];
[glowFourView setAlpha:0.25];
[glowFiveView setAlpha:0.25];
[glowSixView setAlpha:0.25];
[glowSevenView setAlpha:0.25];
[glowEightView setAlpha:0.25];
NSLog(@"Began Button Two");
}
...
(repeating the above pattern to uniquely handle each of the remaining eight images).
The code snippets above will glow the first image touched, but as you drag around the view touchesMoved won't update the alpha for any subsequent image the finger is dragged over, until the touch is released and a new touch is initiated.
The Console shows the touchesMoved NSLog from the first image touched only, and continually repeats the NSLog for that first image touched for as long as the finger is dragged, no matter which image is subsequently under the dragging finger.
I would really appreciate your advice and any example that replaces or updates the above methods to produce the desired result of getting one image at a time to glow, as a finger is dragged over each of a series of images.
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经实现了与你所描述的类似的东西。假设此代码位于包含 Glow 视图的视图中,您需要执行以下操作:1) 让容器视图通过从
hitTest:withEvent: 返回自身来拦截触摸事件,以及 2)在
touchesMoved:withEvent:
中,调用 UIView 的hitTest:withEvent:
实现来确定触摸所在的视图。您可能还需要实现
touchesBegan:withEvent:
在触摸开始移动之前突出显示视图,touchesCancelled:withEvent:
和touchesEnded:withEvent:
取消突出显示所有视图。I've implemented something similar to what you describe. Assuming this code is in the view that contains your Glow views, you need to do a couple of things: 1) have your container view intercept touch events by returning itself from
hitTest:withEvent:
, and 2) intouchesMoved:withEvent:
, call UIView's implementation ofhitTest:withEvent:
to figure out which view the touch is in.You'll probably want to also implement
touchesBegan:withEvent:
to highlight the view before the touch starts moving andtouchesCancelled:withEvent:
andtouchesEnded:withEvent:
to un-highlight all.