gpt4 book ai didi

ios - 如何在调用 SOAP 网络服务时显示图像?

转载 作者:行者123 更新时间:2023-11-29 01:36:34 25 4
gpt4 key购买 nike

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

最佳答案

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

或者,您可以尝试此自定义加载叠加层。我一直在我的一个项目中使用它,效果很好。在这里,在 ImageView 中,我对 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

关于ios - 如何在调用 SOAP 网络服务时显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901384/

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