Iphone performSelectorInBackground并执行UI操作

Iphone performSelectorInBackground并执行UI操作,iphone,Iphone,在应用程序中,我需要将图像从视图中取出。该视图的框架为W 1800和H 1200 除非完成此活动,否则此活动将花费大量时间和屏幕空间 我需要在后台执行此活动,以便用户可以继续其他事情 实现这一目标的最佳途径是什么。我试过了 - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg 但应用程序会崩溃,因为它不允许用户界面操作。如果我和你一起去 - (void)performSelectorOnMainThread:

在应用程序中,我需要将图像从视图中取出。该视图的框架为W 1800和H 1200

除非完成此活动,否则此活动将花费大量时间和屏幕空间

我需要在后台执行此活动,以便用户可以继续其他事情

实现这一目标的最佳途径是什么。我试过了

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg
但应用程序会崩溃,因为它不允许用户界面操作。如果我和你一起去

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
除非此活动完成,否则屏幕将停止

我需要在后台执行以下活动

-(void) PrepareImageData
{
    UIImage* frontViewImage = [self PreparefrontImage:[self GetSavedFrontImage]];
    [self SaveImageinDocumentWithName:frontViewImage FileName:@"frontview.png"];

    UIImage* rearViewImage  = [self PrepareBackImage:[self GetSavedBackImage]];;
    [self SaveImageinDocumentWithName:rearViewImage FileName:@"backview.png"];
}
    -(UIImage*) GetSavedBackImage
    {
        UIImage* background;
        UIImage* messageTextview;
        UIImage* toTextView;
        UIImage* fromTextView;

        background      = [self GetImageFromView:self toRect:self.frame];

        CGRect rect = CGRectMake(0, 0, 1800, 1200);
        UIGraphicsBeginImageContext(rect.size);
        CGPoint backgroundPoint = CGPointMake(0,0);
        [background drawAtPoint:backgroundPoint];
        UIImage* backImage = UIGraphicsGetImageFromCurrentImageContex();
        UIGraphicsEndImageContext();

        return backImage;
    }

    - (UIImage *) GetImageFromView:(UIView *)aView toRect:(CGRect)aRect
    {
        CGSize pageSize = aRect.size;
        UIGraphicsBeginImageContext(pageSize);
        [aView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;

    }
请帮我做这个


谢谢。

我认为您的问题在于视图的大小太大-如果应用程序试图以这种方式操作如此大小的视图,很可能会因为使用太多内存而被操作系统杀死,特别是在iOS 4.x下。UIView过去被限制为1024x1024,这是一个很好的理由


我建议您研究将问题分为多个部分的方法,这些部分可以在不需要太多内存的情况下进行处理。

您需要输入更多与您正试图实现的目标相关的代码“将图像从UIView中删除”?什么您是否有任何代码来演示您的问题?例如,将UIView子类化并重写
+(CALayer*)层
以返回CATiledLayer。你好,安德鲁,你能给我一些线程来实现这类功能吗。