我正在尝试使用带有图像数组的页面控件实现 UIScrollView。我使用了另一个项目的同一段代码,但它不适用于 Xcode 4.5。调试时ScrollView框架属性都是0,但是scrollview Outlet连接良好。图像不显示在卷轴中。这真的很奇怪。我观察到属性不会像以前的版本那样自动合成。这是代码:
@interface dashboardViewController : UIViewController <UIScrollViewDelegate>{
BOOL pageControlBeingUsed;
}
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
- (IBAction)changePage;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"fondo.jpg"]]];
pageControlBeingUsed=NO;
scrollView.delegate=self;
[self buildScrollView];
// Do any additional setup after loading the view.
}
-(void)buildScrollView{
NSArray *imagesQueue = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"icoblog.png"], [UIImage imageNamed:@"icogaleria.png"], [UIImage imageNamed:@"icobio.png"], nil];
for(int i = 0; i < imagesQueue.count; ++i) {
UIImageView *image = [[UIImageView alloc] initWithImage:[imagesQueue objectAtIndex:i]];
CGFloat xOrigin = i * (scrollView.frame.size.width);
image.frame = CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView addSubview:image];
image=nil;
}
scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * imagesQueue.count, self.scrollView.frame.size.height);
}
非常感谢您的帮助。