-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollViewController.m
89 lines (73 loc) · 2.69 KB
/
ScrollViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// NViewController.m
// ScrollView
//
// Created by Tongtong Xu on 14/11/21.
// Copyright (c) 2014年 xxx Innovation Co. Ltd. All rights reserved.
//
#import "ScrollViewController.h"
#import "NormalViewController.h"
#import "TTXTransition.h"
#import "SwipeView.h"
@interface ScrollViewController ()<SwipeViewDataSource,SwipeViewDelegate>
@property (nonatomic, strong) SwipeView *swipeView;
@property (nonatomic, strong) NSMutableArray *items;
@end
@implementation ScrollViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.items = [NSMutableArray array];
for (int i = 0; i < 10; i++)
{
[_items addObject:@(i)];
}
self.automaticallyAdjustsScrollViewInsets = NO;
_swipeView = [[SwipeView alloc] initWithFrame:self.view.bounds];
_swipeView.delegate = self;
_swipeView.dataSource = self;
_swipeView.pagingEnabled = YES;
[self.view addSubview:self.swipeView];
}
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
{
return [_items count];
}
- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index{
NormalViewController *viewController = [[NormalViewController alloc] init];
viewController.view.backgroundColor = [UIColor darkGrayColor];
[self.navigationController pushViewController:viewController animated:YES];
}
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
if (view == nil) {
view = [[UIView alloc] initWithFrame:self.swipeView.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
} else {
label = (UILabel *)[view viewWithTag:1];
}
CGFloat red = arc4random() / (CGFloat)INT_MAX;
CGFloat green = arc4random() / (CGFloat)INT_MAX;
CGFloat blue = arc4random() / (CGFloat)INT_MAX;
view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
label.text = [_items[index] stringValue];
return view;
}
- (CGSize)swipeViewItemSize:(SwipeView *)swipeView
{
return self.swipeView.bounds.size;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
@end