每一个app都应该有一个初始页来指示app的功能或者本次更新的新功能,也可以是广告等等;
这个初始页需要一个控制器吗?不需要,只要一个scrollview,在appdelegate中
[self.window.rootViewController.view addSubview:self.firstUseLoadView];
这个初始页应该由scrollview来实现,新建view
@interface FirstUseLoadView()<UIScrollViewDelegate>
@property (strong, nonatomic) UIScrollView *scrollView; //轮播view
@property (strong, nonatomic) NSArray *images; //多张图片名称
@property (strong, nonatomic) UIButton *myButton; //进入app按钮
@property (strong, nonatomic) NSTimer *timer; // 定时器
@end
然后初始化scrollview,并在scrollview上面add imageview,imageview的图片保存在数组中,并由动态方法实现
-(void)initImage:(NSArray *)images
{
for (int i = 0; i<images.count; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*screen_width, 0, screen_width,screen_height)];
imageView.image = [UIImage imageNamed:images[i]];
imageView.contentMode = UIViewContentModeScaleAspectFit ;
[self.scrollView addSubview:imageView];
if ([self.images.lastObject isEqualToString:self.images[i]]) {
imageView.userInteractionEnabled = YES;
[imageView addSubview:_myButton];
}
}
self.scrollView.contentSize = CGSizeMake((self.images.count+1)*screen_width, screen_height);
}
这里的imageview的size必须是屏幕大小,坐标的x必须递增一个size.width;这个计时器可有可无,主要为了广告准备。
接下来设置分页
#pragma mark -
#pragma mark AutoPicturesShow
//图片自动显示
-(void)autoImageShow{
NSInteger page = [_pageControl currentPage];
if (page == _pageControl.numberOfPages - 1) {
[self enterApp:nil];
}
else{
page ++;
}
_pageControl.currentPage = page;
[self.scrollView setContentOffset:CGPointMake(page * self.bounds.size.width, 0) animated:YES];
}
//点击按钮进入app
-(void)enterApp:(id)sender
{
if ([self.delegate respondsToSelector:@selector(enterLoginViewWithStyle:)]) {
[self.delegate enterLoginViewWithStyle:1];
}
}
#pragma mark -
#pragma UIScrollView Delegate Method
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint offSet = scrollView.contentOffset;
NSInteger currentPicture = (offSet.x+self.bounds.size.width/2)/self.bounds.size.width;
_pageControl.currentPage = currentPicture;
if (self.scrollView.contentOffset.x == (self.images.count)*screen_width) {
if
([self.delegate respondsToSelector:@selector(enterLoginViewWithStyle:)]) {
[self.delegate enterLoginViewWithStyle:2];
}
}
}
这里滑动完滚动页,进入app的按钮可以做成委托,也可以block实现,和点击cell上的按钮一样