所以我有一个自定义的UIView类(我称之为UIStageView
),它模拟了一个提示的外观,在该提示中,背景变暗并将其视图置于中心(下面的代码)。现在,它可以在任何iPad上运行,除了iPad播放。
出于某种原因,触摸会立即通过UIStageView
并进入其父视图。这可能是什么原因?我正在iOS 8.1上运行该项目,甚至当我恢复到7.1时,也会发生错误。请注意,此问题仅发生在iPad Airs(物理和模拟器)上。在iPad 1-4上运行时,它可以正常工作。
// UIStageView
- (id)initWithFrame:(CGRect)frame withTarget:(UIView *)target {
// Init Background
CGFloat screenWidth = target.frame.size.width;
CGFloat screenHeight = target.frame.size.height;
CGRect rFrame = CGRectMake(0, 10, screenWidth, screenHeight);
if (self = [super initWithFrame:rFrame]) {
[self initSubWithFrame:frame withTarget:(UIView *)target];
[self initExtension];
self.userInteractionEnabled = true;
NSLog(@"StageView inited! :)");
}
return self;
}
- (void)initSubWithFrame:(CGRect)frame withTarget:(UIView *)target {
[self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.8]];
_properFrame = frame;
_entranceFrame = CGRectMake(frame.origin.x, frame.origin.y-frame.size.height/2, frame.size.width, frame.size.height);
_babyView = [[UIView alloc] initWithFrame:_entranceFrame];
[_babyView setBackgroundColor:[UIColor whiteColor]];
_babyView.layer.cornerRadius = 15;
_babyView.layer.masksToBounds = YES;
[self addSubview:_babyView];
_target = target;
_indent = 5;
}
基本上,我的代码的工作方式是UIStageView
本身会降级为背景,而_babyView
成为主视图,并且是用户与之交互的内容。
我还有一个方法设置,可以在点击时从其父视图中删除UIStageView
。
这适用于我尝试过的任何iPad(物理和模拟器),除了iPad Airs。有任何想法吗? :\
答案 0 :(得分:0)
修正了它!事实证明,声明@property (nonatomic)float alpha
导致UIView出现故障。我注意到我的UIView
在iPad Air或iPad Retina上都没有接受任何触摸,当我没有明确设置它(即_alpha = .5
)时它只会在我安装时在iPad Air上失败它(即_alpha = .5
)。
编辑: 刚刚发现alpha确实是一个保留字,我从来没有注意到。我的坏:\