在触摸事件中获取自定义SuperView?

时间:2013-04-15 10:06:43

标签: iphone ios

我正在开发一个小游戏,我想在超级视图上做一些功能..超级视图是一个自定义类,即Reflection View..,并希望在用户移动视图时隐藏反射。

这就是我所做的...... (查看代码中的注释以获取详细信息)

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"Touch Began");
    frame2 = dragImageView1.frame;
     NSLog(@"uiview origin: %@", NSStringFromCGPoint(frame2.origin));
     // here i want to get the superview Programatically because i will work on multiple such views and [touch view].superview does not give me the ReflectionView Functions
     [_reflectionView1 hideReflection];
    UITouch *touch = [[event allTouches] anyObject];


      if ([[touch view] tag]!=0) {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        [[touch view] setFrame:CGRectMake(frame2.origin.x, frame2.origin.y, 125.0 * 1.1, 135.0 * 1.1)];
    } else {
        [[touch view] setFrame:CGRectMake(frame2.origin.x, frame2.origin.y, 52.08 * 1.1, 63.28 * 1.1)];
    }
        [self.view bringSubviewToFront:[touch view].superview]; 
      }
}

1 个答案:

答案 0 :(得分:3)

As 0x7fffff提到您需要将超级视图转换为自定义视图。喜欢

[(ReflectionView *)touch.view.superview updateReflection];

如果您确定在哪里调用superview将始终是ReeflectionView,或者如果您使用superview不是Reflection的应用程序将崩溃,请使用此选项。 然后将其添加到您的代码中

if(touch.view.superview isEqual:[ReflectionView class])
{
   [(ReflectionView *)touch.view.superview updateReflection];
}