ios - MWPhotoBrowser 不从 web URL 加载图像

标签 ios swift uiimage mwphotobrowser

我正在使用 MWPhotoBrowser 在我的应用程序中显示单个图像。我在主 Storyboard 中将 View Controller 的类设置为 MWPhotoBrowser,并添加了以下代码,但图像无法加载。

    let photos = NSMutableArray()
    let photo = MWPhoto(URL: NSURL(string: "http://images.nationalgeographic.com/wpf/media-live/photos/000/911/cache/man-ocean-phytoplankton_91111_600x450.jpg"))
    photos.addObject(photo)


    self.photos = photos
    self.displayActionButton = true
    self.displayActionButton = true;
    self.displayNavArrows = true;
    self.displaySelectionButtons = true;
    self.alwaysShowControls = true;
    self.zoomPhotosToFill = true;
    self.enableGrid = true;
    self.startOnGrid = true;
    self.enableSwipeToDismiss = true;

这些是委托(delegate)方法。我注意到我们需要一个返回 MWPhoto 的 photoAtIndex,但委托(delegate)只有一个返回 MWPhotoProtocol 的函数

    func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> UInt
{
    return UInt(photos.count)
}
func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol!
{
    return photos.objectAtIndex(Int(index)) as! MWPhotoProtocol
}

我得到以下屏幕:

enter image description here

最佳答案

首先,MWPhoto 符合MWPhotoProtocol,因此您应该:

var photos = [MWPhoto]()
let photo = MWPhoto(URL: "...")
photos.append(photo)

然后您可以直接返回 photos[index]

编辑 - 你应该阅读你的控制台。使用您提供的 URL,将记录以下内容:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

我将您的链接更改为 https 并且一切正常加载。

关于ios - MWPhotoBrowser 不从 web URL 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37583463/

相关文章:

iOS - 在圆形按钮内制作 UIImage

swift - 是否可以在不更改文本不透明度的情况下以编程方式更改标签背景图像的不透明度? ( swift )

IOS:如何仅使用点击手势即可允许触发的转场和发送的 Action

ios - UIWebView 将 Objective C 暴露给 JavaScript

ios - 从 Facebook 注销 parse.com 用户失败

iphone - 在 uitabbar 应用程序 iOS iPad 中更改当前 View

ios - 带有 UIImage 属性的核心数据 - 使用 UIImage 或 NSData?

swift - 如何在按下通知操作时运行 URL?

Swift SpriteKit 使用结构而不是类来渲染 Sprite

ios - 不立即调用segue