我无法在PageViewController上更改UIImageView的图像

时间:2014-12-12 14:59:18

标签: ios objective-c uiscrollview uiimageview uipageviewcontroller

我使用UIPageViewController,我的每个视图在UIScrollView中都有一个UIImageView。 我希望在方向改变时更改UIImageView的图像。我可以控制更改事件并更改图像,但它不会更改当前视图图像,它会在当前视图之前更改视图。 这是第一个设置和加载图像到UIImageView的方法。

-(void)loadImageToImageView{

UIImage *image =[UIImage imageNamed:self.imageName];

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:image];
[self.scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height)];
[self.scrollView setBackgroundColor:[UIColor blackColor]];

[tempImageView setFrame:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height)];
tempImageView.backgroundColor = [UIColor blackColor];

self.imageView = tempImageView;

[self.imageView setContentMode:UIViewContentModeScaleAspectFit];

self.scrollView.minimumZoomScale = 1;
self.scrollView.maximumZoomScale = 4.0;
self.scrollView.delegate = self;
self.scrollView.zoomScale = 1;

[self.scrollView addSubview:self.imageView];

self.scrollView.bounces = NO;
}

当方向改变时,此方法会触发。

-(void)changeImage{

UIImage *image =[UIImage imageNamed:self.landscapeImage];
[self.imageView setImage:image];

}

1 个答案:

答案 0 :(得分:0)

更改以下UIPageViewControllerDelegate方法

中的图片名称
-(UIViewController *)viewControllerAtIndex:(NSInteger)index {

     PageViewController *childViewController = [[ZoomContainerViewController alloc] initWithNibName:@"ZoomContainerViewController" bundle:nil]; //load the xib file

     childViewController.imageName = requiredImageString;

     return childViewController;

}

然后在PageViewControllerviewdidload()方法中将该图片名称设置为:

 self.backgroundImageView.image = [UIImage imageNamed:self.imageName];