首页 > 代码库 > iOS移动应用开发零碎细节随笔
iOS移动应用开发零碎细节随笔
1.关于视图交互的屏蔽问题
(1)下文代码段表现的视图层次关系是self.view上放置_launchScrollView,而_launchScrollView 上放置了4个launchImageView用来当欢迎界面做应用首次使用介绍,再者最后1个launchImageView中间放置comeinBtn。
(2)现欲comeinBtnClick事件触发,且在默认情况下发现并不可行(userInteractionEnabled 默认为NO)
(3)分析:交互默认为NO,会屏蔽掉launchImageView内子视图所有点击事件和手势,所以必须要打开
1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // Do any additional setup after loading the view. 5 6 NSInteger imageCount = 4; 7 _launchScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, HBScreenWidth, HBScreenHeight)]; 8 _launchScrollView.bounces = NO; 9 _launchScrollView.pagingEnabled = YES;10 _launchScrollView.showsHorizontalScrollIndicator = NO;11 _launchScrollView.contentOffset = CGPointMake(0.0, 0.0);12 _launchScrollView.contentSize = CGSizeMake(HBScreenWidth * imageCount, 0);13 14 //导入图片15 for (NSInteger i = 0; i < imageCount; i++) {16 UIImageView *launchImageView = [[UIImageView alloc]initWithFrame:CGRectMake(HBScreenWidth * i, 0.0, HBScreenWidth, HBScreenHeight)];17 UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"start_h%d", i + 1]];18 image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0) resizingMode:UIImageResizingModeStretch];19 launchImageView.image = image;20 21 //此处交互默认为NO,会屏蔽掉launchImageView内子视图所有点击事件和手势,所以必须要打开22 launchImageView.userInteractionEnabled = YES;23 24 if (i == 3) {25 UIButton *comeinBtn = [UIButton buttonWithType:UIButtonTypeCustom];26 comeinBtn.frame = CGRectMake(HBScreenWidth * 0.42, HBScreenHeight * 0.6 , HBScreenWidth * 0.17, HBScreenHeight * 0.08);27 comeinBtn.backgroundColor = [UIColor colorWithRed:197/255.0 green:233/255.0 blue:250/255.0 alpha:1.0];28 comeinBtn.layer.borderWidth = 1.0;29 comeinBtn.titleLabel.font = [UIFont fontWithName:nil size:15.0];30 [comeinBtn setTitle:@"点击进入" forState:UIControlStateNormal];31 [comeinBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];32 [comeinBtn addTarget:self action:@selector(comeinBtnClick) forControlEvents:UIControlEventTouchUpInside];33 [launchImageView addSubview:comeinBtn];34 }35 [_launchScrollView addSubview:launchImageView];36 }37 [self.view addSubview:_launchScrollView];38 }
iOS移动应用开发零碎细节随笔
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。