0
我想創建一個滾動視圖並向它添加2個xib屏幕(SVPage1.xib和SVPage2.xib),這樣我就可以翻轉兩個屏幕。UIScrollView /向它添加xibs
我創建了scrollview和Page Control對象。
這是我在.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"SVPage1" owner:self options:nil];
UIView *mainView = [subviewArray objectAtIndex:0];
[self.scrollView addSubview:mainView];
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * 2;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
NSArray *subviewArray2 = [[NSBundle mainBundle] loadNibNamed:@"SVPage2" owner:self options:nil];
UIView *mainView2 = [subviewArray2 objectAtIndex:0];
[self.scrollView addSubview:mainView2];
//Set the content size of our scrollview according to the total width of our imageView objects.
scrollView.contentSize = CGSizeMake(mainView.frame.size.width * 3, mainView2.frame.size.height);
}
#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1;
self.pageControl.currentPage = page;
}
我相信,當我打開第二XIB文件我加載它在第一個。
當我運行程序時,我在屏幕上看到第二個xib文件,當我翻閱其他頁面時,它們是空白的。我想我正在做一些可怕的錯誤嘗試添加第二個.xib ...
任何想法?
基本上,你是對的:)謝謝! – Darko 2013-05-10 19:58:40