我想向我的滚动视图添加页面控件,并且遵循了大量的网络教程,其中大部分使用与此相同的代码tutorial.但是,一旦将代码放入我的项目,甚至在我对代码进行更改以尝试使其工作的情况下,它也不会。我已经设法让代码在页面控件被按下时工作,但它不适用于页面滚动。我的问题与this类似,但答案没有帮助。这里是我的代码:页面滚动视图滚动时控件不会更改
MainViewController.h
@interface MainViewController : UIViewController
{
UIScrollView *svCollegeMain;
UIScrollView *svCollegePage;
UIPageControl *pcCollege;
UIView *viewP1;
}
@property (nonatomic, retain) IBOutlet UIScrollView* svCollegeMain;
@property (nonatomic, retain) IBOutlet UIScrollView* svCollegePage;
@property (nonatomic, retain) IBOutlet UIPageControl * pcCollege;
- (IBAction)changePage;
@end
和MainViewController.m
@implementation MainViewController
@synthesize svCollegeMain, svCollegePage, pcCollege;
- (void)viewDidLoad
{
[super viewDidLoad];
self.svCollegeMain.contentSize = CGSizeMake(960, 332);
self.svCollegePage.contentSize = CGSizeMake(320, 500);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
CGFloat pageWidth = 320;
int page = floor((svCollegeMain.contentOffset.x - pageWidth/2)/pageWidth) + 1;
pcCollege.currentPage = page;
}
- (IBAction)changePage
{
CGRect frame;
frame.origin.x = self.svCollegeMain.frame.size.width * self.pcCollege.currentPage;
frame.origin.y = 0;
frame.size = self.svCollegeMain.frame.size;
[self.svCollegeMain scrollRectToVisible:frame animated:YES];
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
self.svCollegeMain = nil;
self.svCollegePage = nil;
self.pcCollege = nil;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
只是柜面这使得任何区别,我的观点阐述了观点,那么主滚动这个视图中的视图和页面控制,主滚动视图中的另一个视图和滚动视图(彼此相邻),最后是第二个滚动视图中的最终视图(全部在IB中,不需要太多的代码)以及所有内容在IB中链接起来。
Thankyou SOOO很多!每次我检查代码时,该行都直接从我身边飞过。那和下面的一行都是它所花费的:svCollegeMain.delegate = self; (.m)和.h中的。谢谢 –