这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[self colorWithHexString:@"d944f7"]];
self.pageControl = [[UIPageControl alloc] init];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 0, self.view.frame.size.width - 20, self.view.frame.size.height)];
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = NO;
self.scrollView.pagingEnabled = YES;
self.automaticallyAdjustsScrollViewInsets = NO;
self.scrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);
[self.view addSubview:self.scrollView];
}
- (void)reloadData
{
self.pageControl.numberOfPages = self.sectionsArray.count;
self.pageControl.currentPage = 0;
self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:(rand()%256)/256.0 green:(rand()%256)/256.0 blue:(rand()%256)/256.0 alpha:1];
self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:(rand()%256)/256.0 green:(rand()%256)/256.0 blue:(rand()%256)/256.0 alpha:1];
self.pageControl.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height - 20);
self.pageControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.pageControl];
self.scrollView.contentOffset = CGPointMake(0, 0);
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width*self.pageControl.numberOfPages, self.scrollView.frame.size.height);
NSMutableArray *array = [NSMutableArray array];
NSMutableArray *mvcs = [NSMutableArray array];
NSMutableArray *shadows = [NSMutableArray array];
for (int i = 0 ; i < self.pageControl.numberOfPages; i ++) {
UIView *shadow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width - 20, self.scrollView.frame.size.height - 80)];
shadow.backgroundColor = [UIColor grayColor];
shadow.alpha = 1;
CGPoint pageCenter = CGPointMake((i + 0.5)*self.scrollView.frame.size.width, self.scrollView.frame.size.height/2.0);
shadow.center = pageCenter;
// [shadows addObject:shadow];
//[self.scrollView addSubview:shadow];
MDIMovingView *mv = [[MDIMovingView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width - 5, self.scrollView.frame.size.height - 80)];
mv.identity = 1;
mv.delegate = self;
mv.moveEnabled=NO;
mv.backgroundColor = [self colorWithHexString:@"e6e6e6"];
mv.center = pageCenter;
mv.layer.cornerRadius=10;
mv.clipsToBounds=NO;
[array addObject:mv];
[self.scrollView addSubview:mv];
UIView *topHeader=[[UIView alloc] initWithFrame:CGRectMake(0, 0, mv.frame.size.width, 50)];
[topHeader setRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:10.0];
[topHeader setBackgroundColor:[self colorWithHexString:@"dca2e8"]];
[mv addSubview:topHeader];
UIView *invisibleSeperator =[[UIView alloc] initWithFrame:CGRectMake(0, 50, mv.frame.size.width, 2)];
[invisibleSeperator setBackgroundColor:[self colorWithHexString:@"d944f7"]];
[mv addSubview:invisibleSeperator];
MDITableViewController *vc = [[MDITableViewController alloc] init];
[mvcs addObject:vc];
vc.objects = self.sortedTasksArray[i];
vc.delegate = self;
vc.dataSoure = self;
vc.movingViewDelegate = self;
[self addChildViewController:vc];
vc.view.frame = CGRectMake(5, 60, mv.frame.size.width - 10, mv.frame.size.height - 80);
[mv addSubview:vc.view];
}
self.shadowViews = shadows;
self.movingViews = array;
self.tableVCs = mvcs;
}
这是它的作用——注意导航栏和移动视图之间的空间: