2

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

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

-(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]; 
      }
}
4

1 回答 1

3

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

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

如果您确定在哪里调用它,而超级视图将始终是 ReeflectionView,则使用它,否则如果您在超级视图不是反射的情况下使用它,您的应用程序将崩溃。然后将此添加到您的代码中

if(touch.view.superview isEqual:[ReflectionView class])
{
   [(ReflectionView *)touch.view.superview updateReflection];
}
于 2013-06-23T08:27:58.480 回答