简单的手动轮播图
先在点h初始化一个方法+ (BOOL)isShow;
。。。。MMM
#import "ViewController.h"
#import "ViewController1.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic , strong) UIScrollView *scrollView;
@end
@implementation ViewController
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self scrollViewItem];
}
-(void)scrollViewItem
{
self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
self.scrollView.delegate = self;
self.scrollView.contentSize = CGSizeMake(3 * self.view.frame.size.width, self.view.frame.size.height);
self.scrollView.bounces = NO;
self.scrollView.pagingEnabled = YES;
self.scrollView.showsVerticalScrollIndicator = NO;
for (int i = 0; i < 3; i++){
UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSArray *arr = @[@"Lun1", @"Lun2", @"Lun3"];
imgV.image = [UIImage imageNamed:arr[i]];
if (i == 2){
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(150, 400, 100, 40)];
[imgV addSubview:btn];
// btn.sd_layout.topSpaceToView(self 20).leftSpaceToView(self, 300).widthIs(90).heightIs(30);
[btn setTitle:@"立即体验" forState:(UIControlStateNormal)];
[btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
btn.backgroundColor = [UIColor blueColor];
[btn addTarget:self action:@selector(btnClick) forControlEvents:(UIControlEventTouchUpInside)];
imgV.userInteractionEnabled = YES;
}
[ self.scrollView addSubview:imgV];
}
[self.view addSubview: self.scrollView];
}
-(void)btnClick{
ViewController1 *v1 = [[ViewController1 alloc]init];
[self presentViewController:v1 animated:YES completion:nil];
NSLog(@"点击了");
}
- (void) btnClick{
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(btnClick)]) {
[self.delegate btnClick];
}
}
+ (BOOL)isShow{
// 读取版本信息
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSString *localVersion = [user objectForKey:VERSION_INFO_CURRENT];
NSString *currentVersion =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
if (localVersion == nil || ![currentVersion isEqualToString:localVersion]) {
[XTGuidePagesViewController saveCurrentVersion];
return YES;
}else{
return NO;
}
}
// 保存版本信息
+ (void)saveCurrentVersion{
NSString *version =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
[user setObject:version forKey:VERSION_INFO_CURRENT];
[user synchronize];
}
然后在到AppDelegate.m
- (void) btnClick{
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
[self.window.layer transitionWithAnimType:TransitionAnimTypeRamdom subType:TransitionSubtypesFromRamdom curve:TransitionCurveRamdom duration:1.0f];
}
网友评论