我正在尝试在网址中显示带有“https”的图片,但我不知道为什么它没有显示。 (例如https://www.starkmedia.com/blog/wp-content/uploads/2016/02/https.png)。我不知道出了什么问题,因为我也没有任何例外。有人可以帮我弄清楚出了什么问题以及我如何正确显示图像?
我是Xcode的新手,我只是想对其他开发人员编写的代码进行一些更改。
- (void)downloadImageFromUrl:(NSString *)urlString
{
NSLog(@"Url String: %@", urlString);
self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, 179, 245)];
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:urlString]];
self.imageView.image = [UIImage imageWithData:imageData];
self.imageView.userInteractionEnabled = YES;
self.imageView.autoresizesSubviews = YES;
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self showImage];
}
- (void)showImage
{
if ([self.scrollView.subviews count] == 3) {
[self.imageView removeFromSuperview];
}
self.scrollView.alpha = 1;
self.imageView = [[UIImageView alloc] initWithImage:self.image];
self.imageView.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=self.image.size};
[self.scrollView addSubview:self.imageView];
// 2
self.scrollView.contentSize = self.image.size;
// 3
UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(scrollViewDoubleTapped:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
[self.scrollView addGestureRecognizer:doubleTapRecognizer];
UITapGestureRecognizer *twoFingerTapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(scrollViewTwoFingerTapped:)];
twoFingerTapRecognizer.numberOfTapsRequired = 1;
twoFingerTapRecognizer.numberOfTouchesRequired = 2;
[self.scrollView addGestureRecognizer:twoFingerTapRecognizer];
// 4
CGRect scrollViewFrame = self.scrollView.frame;
CGFloat scaleWidth = scrollViewFrame.size.width / self.scrollView.contentSize.width;
CGFloat scaleHeight = scrollViewFrame.size.height / self.scrollView.contentSize.height;
CGFloat minScale = MIN(scaleWidth, scaleHeight);
self.scrollView.minimumZoomScale = minScale;
// 5
NSString *model = [[UIDevice currentDevice] model];
if([model isEqualToString:@"iPad"]) {
self.scrollView.maximumZoomScale = 1.5f;
}
else {
self.scrollView.maximumZoomScale = 1.5f;
}
self.scrollView.zoomScale = minScale;
// 6
[self centerScrollViewContents];
}
答案 0 :(得分:0)
有两种方法可以执行此操作手动添加或使用Pod
1.将SDWebImage文件夹添加到您的应用程序中。
3.现在在头文件中导入它。
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
4.使用以下代码
[self.imageView sd_setImageWithURL:[NSURL URLWithString:"yoururl.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
5.Done。
这将帮助您查看依赖项何时获得新的更新。您还将知道您使用的是哪个版本。这是一个很好的做法。
1.您可以使用Cocoapods。转到您的终端,输入:
$ sudo gem install cocoapods
2.然后转到项目文件夹(地方,您有xcodeproj)并输入:
$ pod init
3.这会创建一个名为Podfile的文件。打开并粘贴:
platform :ios, '8.0' // or whatever you need
use_frameworks!
pod 'SDWebImage', '~> 3.7'
4.所以当你准备就绪时,打开终端并输入:
$ pod install
5.从现在起,您应该使用xcworkspace而不是od xcodeproj。
6.现在在头文件中导入它。
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIImageView+WebCache.h"
4.使用以下代码
[self.imageView sd_setImageWithURL:[NSURL URLWithString:"yoururl.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
5.Done。
希望这有帮助。