Imagescrollview显示黑屏而不是图像

时间:2012-09-29 18:59:20

标签: iphone uiscrollview ios6

点击图库按钮时会显示黑屏

UIButton *galleryButton = [UIButton buttonWithType:UIButtonTypeCustom];

[galleryButton addTarget:self action:@selector(ScrollView:) forControlEvents:UIControlEventTouchUpInside];

galleryButton.frame = CGRectMake(0, 0, 30, 30);

UIImage *ime = [UIImage imageNamed:@"photos.png"];

[galleryButton setImage:ime forState:UIControlStateNormal];

UIBarButtonItem *gallerybutton = [[UIBarButtonItem alloc] initWithCustomView:galleryButton];

-(void)ScrollView:(id)sender
 {
ImageScrollViewController *imagescrollviewcontroller = [[ImageScrollViewController alloc] init];

[self presentViewController:imagescrollviewcontroller animated:YES completion:NULL];

[imagescrollviewcontroller release];


 }

- (void)viewDidLoad
{

 self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

 [_imageScrollView setBackgroundColor:[UIColor blackColor]];
[_imageScrollView setCanCancelContentTouches:NO];
_imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_imageScrollView.clipsToBounds = YES;       // default is NO, we want to restrict drawing within our scrollview
_imageScrollView.scrollEnabled = YES;

   _imageScrollView.pagingEnabled = YES;


 // load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];


    CGRect rect = imageView.frame;
    rect.size.height = kScrollObjHeight;
    rect.size.width = kScrollObjWidth;
    imageView.frame = rect;
    imageView.tag = i;  
    [_imageScrollView addSubview:imageView];
    //[imageView release];
}

[self layoutScrollImages];


  - (void)layoutScrollImages
   {
UIImageView *view = nil;
NSArray *subviews = [_imageScrollView subviews];

// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
    if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
    {
        CGRect frame = view.frame;
        frame.origin = CGPointMake(curXLoc, 0);
        view.frame = frame;

        curXLoc += (kScrollObjWidth);
    }
}

 // set the content size so it can be scrollable
 [_imageScrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [_imageScrollView bounds].size.height)];
    }

任何想法为什么它不显示图像而是黑屏。我正在关注滚动图像的苹果示例代码。我所做的更改是它们在scrollview中显示两个子视图。我只显示一个子视图。

感谢您的帮助。

0 个答案:

没有答案