【问题标题】:How to show images while call a soap web service?如何在调用肥皂网络服务时显示图像?
【发布时间】:2015-10-02 06:02:03
【问题描述】:

我正在构建一个使用来自 Soap Web 服务的数据的应用程序,我只想在屏幕上显示几个图像,让用户知道数据是从网络下载的,我该怎么做?

【问题讨论】:

    标签: ios objective-c iphone web-services soap


    【解决方案1】:

    我建议你试试MBProgressHUD。当工作在后台线程中完成时,Tt 会显示一个带有指示器和/或标签的半透明 HUD。它工作得很好。请探索它!

    或者,您可以尝试这个自定义加载叠加层。我一直在我的一个项目中使用它,效果很好。在这里,在图像视图中,我为 10 个不同的图像设置动画,以便在屏幕上看起来不错。您可以根据需要删除动画并传递自己的图像。

    #import "MyLoadingOverlay.h"
    
    @implementation MyLoadingOverlay
    
    + (id)loadingOverlayInView:(UIView *)iSuperview {
        return [MyLoadingOverlay loadingOverlayInView:iSuperview title:nil fullScreen:NO spinner:YES showCustomImages:NO];
    }
    
    
    + (id)loadingOverlayInView:(UIView *)iSuperview title:(NSString *)iTitle fullScreen:(BOOL)iFullscreen spinner:(BOOL)iShowSpinner {
        return [MyLoadingOverlay loadingOverlayInView:iSuperview title:iTitle fullScreen:iFullscreen spinner:iShowSpinner showCustomImages:NO];
    }
    
    
    + (id)loadingOverlayInView:(UIView *)iSuperview title:(NSString *)iTitle fullScreen:(BOOL)iFullscreen spinner:(BOOL)iShowSpinner showCustomImages:(BOOL)iShowCustomImages {
        MyLoadingOverlay *anOverlay = [[MyLoadingOverlay alloc] initWithFrame:[iSuperview bounds]];
    
        if (!anOverlay) {
            return nil;
        }
    
        // Set our full screen attribute
        anOverlay.fullScreen = iFullscreen;
        anOverlay.showSpinner = iShowSpinner;
    
        anOverlay.userInteractionEnabled = YES;
        anOverlay.opaque = NO;
        anOverlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
        [iSuperview addSubview:anOverlay];
    
        CGFloat theLabelWidth = anOverlay.frame.size.width;
        const CGFloat DEFAULT_LABEL_HEIGHT = 50.0;
        CGRect aFrame = CGRectMake(0, 0, theLabelWidth, DEFAULT_LABEL_HEIGHT);
    
        UILabel *aLabel = [[UILabel alloc] initWithFrame:aFrame];
    
        if (iTitle) {
            aLabel.text = iTitle;
            aLabel.textColor = [UIColor whiteColor];
            aLabel.backgroundColor = [UIColor clearColor];
            aLabel.textAlignment = NSTextAlignmentCenter;
            aLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
            aLabel.shadowColor = [UIColor blackColor];
            aLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
            aLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
            [anOverlay addSubview:aLabel];
        }
    
        CGFloat aLabelYOffset = 0;
    
        if (anOverlay.showSpinner && !iShowCustomImages) {
            UIActivityIndicatorView *aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
            [anOverlay addSubview:aSpinner];
            aSpinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
            [aSpinner startAnimating];
    
            CGRect aSpinnerRect = aSpinner.frame;
            aSpinnerRect.origin.x = floorf(0.5 * (anOverlay.frame.size.width - aSpinnerRect.size.width));
            aSpinnerRect.origin.y = floorf(0.5 * (anOverlay.frame.size.height - aSpinnerRect.size.height));
            aSpinner.frame = aSpinnerRect;
    
            aLabelYOffset = aSpinnerRect.origin.y + 32.0;
        } else {
            UIImage *aMyImage = [UIImage animatedImageNamed:@"My_Loading_" duration:1.0];
            aLabel.textColor = [UIColor colorWithRed:185.0/255.0 green:185.0/255.0 blue:185.0/255.0 alpha:1.0];
            UIImageView *anImageView = [[UIImageView alloc] initWithImage:aMyImage];
            anImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
            [anOverlay addSubview:anImageView];
    
            CGRect anImageRect = anImageView.frame;
            anImageRect.origin.x = floorf(0.5 * (anOverlay.frame.size.width - anImageRect.size.width));
            anImageRect.origin.y = floorf(0.5 * (anOverlay.frame.size.height - anImageRect.size.height));
            anImageView.frame = anImageRect;
    
            aLabelYOffset = anImageRect.origin.y + 32.0;    
        }
    
        aFrame.origin.x = floorf(0.5 * (anOverlay.frame.size.width - theLabelWidth));
        aFrame.origin.y = aLabelYOffset;    
        aLabel.frame = aFrame;
    
        // Set up the fade-in animation
        CATransition *aTransition = [CATransition animation];
        [aTransition setType:kCATransitionFade];
        [[iSuperview layer] addAnimation:aTransition forKey:@"layerAnimation"];
    
        return anOverlay;
    }
    
    
    #pragma mark -
    #pragma instance methods
    
    - (void)addToView:(UIView *)iSuperview {
        [iSuperview addSubview:self];
        // Set up the fade-in animation
        CATransition *aTransition = [CATransition animation];
        [aTransition setType:kCATransitionFade];
        [[iSuperview layer] addAnimation:aTransition forKey:@"layerAnimation"];
    }
    
    
    - (void)removeView {
        if (self.fullScreen) {
            [UIView animateWithDuration:0.3 animations:^{
                self.alpha = 0.0;
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
            }];
        } else {
            UIView *aSuperview = [self superview];
            [super removeFromSuperview];
            // Set up the animation for image loading overlay
            CATransition *aTransition = [CATransition animation];
            [aTransition setType:kCATransitionFade];
    
            [[aSuperview layer] addAnimation:aTransition forKey:@"layerAnimation"];
        }
    }
    
    
    - (void)drawRect:(CGRect)iRect {
        if (!self.fullScreen) {
            iRect.size.height -= 1;
            iRect.size.width -= 1;
    
            const CGFloat RECT_PADDING = 4.0;
            iRect = CGRectInset(iRect, RECT_PADDING, RECT_PADDING);
    
            const CGFloat ROUND_RECT_CORNER_RADIUS = 5.0;
            CGPathRef aPath = copyPathWithRoundRect(iRect, ROUND_RECT_CORNER_RADIUS);
    
            CGContextRef aContext = UIGraphicsGetCurrentContext();
    
            const CGFloat BACKGROUND_OPACITY = 0.0;
            CGContextSetRGBFillColor(aContext, 0, 0, 0, BACKGROUND_OPACITY);
            CGContextAddPath(aContext, aPath);
            CGContextFillPath(aContext);
    
            const CGFloat STROKE_OPACITY = 0.25;
            CGContextSetRGBStrokeColor(aContext, 1, 1, 1, STROKE_OPACITY);
            CGContextAddPath(aContext, aPath);
            CGContextStrokePath(aContext);
            CGPathRelease(aPath);
        } else {
            CGContextRef aContext = UIGraphicsGetCurrentContext();
            const CGFloat BACKGROUND_OPACITY = 0.75;
            CGContextSetRGBFillColor(aContext, 0, 0, 0, BACKGROUND_OPACITY);
            CGContextFillRect(aContext, iRect);
        }
    }
    
    
    @end
    

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2017-01-16
      • 2017-12-10
      相关资源
      最近更新 更多