我有一个类imageView
的类变量UIImageView
和一个按钮。
使用Assets从Gallery中加载图像数组。
完成所有图像的加载后,我会显示第一张图像:
- (void)showImage
{
if ([images count] > 0)
[self.imageView setImage:[images objectAtIndex:0]];
currentPage = 0;
}
到目前为止一切都很好,
但是当我按下按钮并执行以下操作时:
- (IBAction)buttonNext:(id)sender {
NSLog(@"images array %@", images );
if (currentPage < [images count]-1)
{
NSLog(@"next currentPage %d %d %@",currentPage, [images count],[images objectAtIndex:currentPage])
currentPage++;
[self.imageView setImage:[images objectAtIndex:currentPage]];
}
}
不会发生图像替换。 imageView
卡住了上一张图片。
我调试了图像数组:
images array (
"<UIImage: 0xb38cec0>",
"<UIImage: 0xb0f8280>",
"<UIImage: 0xb063360>",
"<UIImage: 0xb0660a0>"
)
修改 加载图像的代码:
-(void)loadImage:(NSString*)url
{
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
UIImage *largeImage = [UIImage imageWithCGImage:iref];
CGSize size=CGSizeMake(400, 500);//set the width and height
UIGraphicsBeginImageContext(size);
[largeImage drawInRect:CGRectMake(0,0,size.width,size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
//here is the scaled image which has been changed to the size specified
UIGraphicsEndImageContext();
[images addObject:newImage];
if ([images count] == [pages count])
[self showImage];
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};
NSURL *asseturl = [NSURL URLWithString:url];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];
}
- (void)viewWillAppear:(BOOL)animated
for(NSDictionary* a in pages)
{
if ([a objectForKey:@"iospath"] != nil)
[self loadImage:[document objectForKey:@"iospath"]];
}
pages
是在viewDidLoad中加载的数组。图像在那里。为什么我不能炫耀?
此致