我正在使用 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
}
我得到以下屏幕:
最佳答案
首先,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/