0

很抱歉这个模糊的问题,但我不知道如何使它更具体,因为我不知道代码有什么问题。你们可能会立即知道这些错误的含义。

我正在尝试在应用程序启动时显示覆盖图像,然后通过点击手势使覆盖消失。我只是无法让它工作。我从另一个 SO 问题中获得了代码(链接:创建点击覆盖指令视图)。有什么想法我在这里想念的吗?我的代码显示了我收到的错误消息(2 个错误,1 个警告)。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIImageView *overlay = [[UIImageView alloc]
                            initWithImage:[UIImage imageNamed:@"overlayImg.png"]];
    [self.window addSubview:overlay];

    UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    recognizer.delegate = self; //WARNING: Assigning to 'id<UIGestureRecognizerDelegate>'from incompatible type 'AppDelegate *const__strong'
    [overlay addGestureRecognizer:recognizer];
    overlay.userInteractionEnabled =  YES;
    self.overlay = overlay; //ERROR: Property 'overlay' not found on object of type 'AppDelegate *'
    // Override point for customization after application launch.
    return YES;
}

- (void) handleTap:(UITapGestureRecognizer *)recognizer
{
    [self.overlay removeFromSuperView]; //ERROR: Property 'overlay' not found on object of type 'AppDelegate *'
}
4

1 回答 1

1

您可以删除该行

recognizer.delegate = self;

或实现委托。将此添加到 AppDelegate.m 的顶部以消除警告。

@interface AppDelegate () <UIGestureRecognizerDelegate>

@end

看起来,您缺少该UIImageView属性。将属性添加到上面的接口扩展中。这应该是这样的:

@interface AppDelegate () <UIGestureRecognizerDelegate>
@property (nonatomic, strong) UIImageView *overlay;
@end
于 2012-12-18T16:50:31.680 回答