gpt4 book ai didi

iphone - ALAssetLibrary 和 iOS 5.0

转载 作者:行者123 更新时间:2023-12-03 21:04:50 24 4
gpt4 key购买 nike

我编写了一个简单的方法来从资源库中获取数据,该方法在 iOS4.3 上运行良好,但在 iOS5 中获取图像时会出现延迟。我应该怎么做才能加快 iOS 5 上的获取过程。

-(void)setImages
{
int count =0;
int photoNumber = [[templateDictionary objectForKey:@"ElementsOnPage"] intValue];
for (int i=currentCount; count<photoNumber; i++) {
[self data:count+1 count:i];
count++;
}
}


-(void)data:(int)photoNumber count:(int)currentCount
{
NSURL *url;
UIImageView *firstImageView = [[UIImageView alloc]init];
CGFloat x,y,wid,h;
float ang;
if (currentCount>=[ImageURLArray count]) {
[firstImageView release];
return;
}
else
{
url = [NSURL URLWithString:[ImageURLArray objectAtIndex:currentCount]];
switch (photoNumber) {
case 1:
{

x = [[templateDictionary objectForKey:@"FirstElement_X"]floatValue];
y=[[templateDictionary objectForKey:@"FirstElement_Y"]floatValue];
wid = [[templateDictionary objectForKey:@"FirstElement_Width"]floatValue];
h=[[templateDictionary objectForKey:@"FirstElement_Height"]floatValue];
ang =[[templateDictionary objectForKey:@"FirstElement_Angle"]floatValue];
firstImageView.tag = 1+10;
//FirstImage

}
break;
case 2:
{
x = [[templateDictionary objectForKey:@"SecondElement_X"]floatValue];
y=[[templateDictionary objectForKey:@"SecondElement_Y"]floatValue];
wid = [[templateDictionary objectForKey:@"SecondElement_Width"]floatValue];
h=[[templateDictionary objectForKey:@"SecondElement_Height"]floatValue];
ang =[[templateDictionary objectForKey:@"SecondElement_Angle"]floatValue];
firstImageView.tag=2+10;
//SecondImage

}
break;
case 3:
{
x = [[templateDictionary objectForKey:@"ThirdElement_X"]floatValue];
y=[[templateDictionary objectForKey:@"ThirdElement_Y"]floatValue];
wid = [[templateDictionary objectForKey:@"ThirdElement_Width"]floatValue];
h=[[templateDictionary objectForKey:@"ThirdElement_Height"]floatValue];
ang =[[templateDictionary objectForKey:@"ThirdElement_Angle"]floatValue];
firstImageView.tag = 3+10;
//ThirdImage
}
break;
default:
break;
}
[firstImageView setFrame:CGRectMake(x, y, wid, h)];

dispatch_async(dispatch_get_main_queue(), ^
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.

[library assetForURL:url

resultBlock:^(ALAsset* asset)
{

UIImage* img = [UIImage imageWithCGImage:[asset.defaultRepresentation fullResolutionImage]];
[firstImageView setImage:img];

}
failureBlock:^(NSError* error)
{
NSLog(@"error requesting asset");
}
];

[library release];

// Group enumerator Block
[pool release];
});


if ([[contentType objectAtIndex:currentCount]isEqualToString:@"1"]) {
UIButton *videoImage = [[UIButton alloc]initWithFrame:CGRectMake((firstImageView.frame.size.width/2)-25,(firstImageView.frame.size.height/2)-25,50,50)];
videoImage.transform = CGAffineTransformMakeRotation(ang*(3.14/180));
[videoImage setBackgroundImage:[UIImage imageNamed:@"videothumb.png"] forState:UIControlStateNormal];
[videoImage addTarget:self action:@selector(PlayMusicOnClickofButton:) forControlEvents:UIControlEventTouchUpInside];
[firstImageView addSubview:videoImage];
videoImage.tag = currentCount+1000;
[videoImage release];
}
}
firstImageView.transform = CGAffineTransformMakeRotation(ang*(3.14/180));
firstImageView.userInteractionEnabled = YES;
[coverImageView addSubview:firstImageView];
[coverImageView setImage:[UIImage imageNamed:innerBackground]];

[firstImageView release];

}

最佳答案

我已经向 Apple 报告了 iOS5 中 assetForUrl 性能下降的错误(根据开发论坛中 Apple 员工的请求)。

背景:assetLibrary 已重构,现在基于 CoreData,在每次 assetForUrl 调用时,SDK 实际上会打开一个新的 SQLite 连接(BAH...),导致性能显着下降。

临时解决方案:在我的应用程序中,我需要使用 assetForUrl 加载 200 张图片。在 iOS4 中需要 100 毫秒,在 iOS5 中大约需要 5 秒以上。我发现枚举整个库(大约 1500 张图片)并将其缓存在 URL-->ASSET 字典中大约需要 3 秒。我现在正在使用这种技术。如果您保留旧 Assets 并且库发生更改,请注意这些 Assets 。

关于iphone - ALAssetLibrary 和 iOS 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8400170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com