对于模糊的问题感到抱歉,但我不知道如何使其更具体,因为我不知道代码有什么问题。你们可能会马上告诉那些错误是什么意思。
我正在尝试让应用程序启动时显示叠加图像,然后使用点按手势使叠加层消失。我只是无法让这个工作。我从不同的SO问题中得到了代码(链接:Create click-through overlay instruction view)。 我在这里缺少什么想法?我的代码显示了我收到的错误消息(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 *'
}
答案 0 :(得分:1)
您可以删除该行
recognizer.delegate = self;
或实施委托。在AppDelegate.m的顶部添加它以消除警告。
@interface AppDelegate () <UIGestureRecognizerDelegate>
@end
看起来,你错过了UIImageView
财产。
转到并将属性添加到上面的接口扩展。这应该是这样的:
@interface AppDelegate () <UIGestureRecognizerDelegate>
@property (nonatomic, strong) UIImageView *overlay;
@end