我已经设法显示图像.不幸的是,当我将UIImageVIEw模式更改为Aspect fill时,图像变得比它应该更大.
这里是图片:
https://dl.dropboxusercontent.com/u/86529526/pic_normal.png
https://dl.dropboxusercontent.com/u/86529526/pic_error.png
在pic_normal中,您将看到两个单元格,具有两个正常图像.
在pic_error中,您将第二个单元格被第一个单元格图像覆盖.
有人可以帮我解决这个问题吗?我也把我的整个代码放在这里:
import UIKitclass tableVIEwController: PFquerytableVIEwController,UISearchbarDelegate { @IBOutlet var searchbar: UISearchbar! // Initialise the PFquerytable tablevIEw overrIDe init(style: UItableVIEwStyle,classname: String!) { super.init(style: style,classname: classname) } required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) // Configure the PFquerytableVIEw self.pullToRefreshEnabled = true self.paginationEnabled = false } // define the query that will provIDe the data for the table vIEw overrIDe func queryFortable() -> PFquery { // Start the query object var query = PFquery(classname: "Places") // query with pointer query.includeKey("mainPhoto") // Add a where clause if there is a search criteria if searchbar.text != "" { query.whereKey("name",containsstring: searchbar.text) } // Order the results query.orderByAscending("name") // Return the qwuery object return query } //overrIDe func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell overrIDe func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath,object: PFObject) -> PFtableVIEwCell? { var cell = tableVIEw.dequeueReusableCellWithIDentifIEr("CustomCell") as! CustomtableVIEwCell! if cell == nil { cell = CustomtableVIEwCell(style: UItableVIEwCellStyle.Default,reuseIDentifIEr: "CustomCell") } // Extract values from the PFObject to display in the table cell if let name = object["name"] as? String{ cell.name.text = name } // display initial image var initialthumbnail = UIImage(named: "question") cell.photo.image = initialthumbnail // extract image from pointer if let pointer = object["mainPhoto"] as? PFObject { cell.detail.text = pointer["photoTitle"] as? String! if let thumbnail = pointer["photo"] as? PFfile { cell.photo.file = thumbnail cell.photo.loadInBackground() } } cell.sendSubvIEwToBack(cell.photo) // return the cell return cell } // In a storyboard-based application,you will often want to do a little preparation before navigation overrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) { // Get the new vIEw controller using [segue destinationVIEwController]. var detailScene = segue.destinationVIEwController as! DetailVIEwController // Pass the selected object to the destination vIEw controller. if let indexPath = self.tableVIEw.indexPathForSelectedRow() { let row = Int(indexPath.row) detailScene.currentObject = objects[row] as? PFObject } } overrIDe func vIEwDIDLoad(){ super.vIEwDIDLoad() let tapGesture = UITapGestureRecognizer(target:self,action:Selector("hIDeKeyboard")) tapGesture.cancelstouchesInVIEw = true tableVIEw.addGestureRecognizer(tapGesture) } func hIDeKeyboard(){ tableVIEw.endEditing(true) } overrIDe func vIEwDIDAppear(animated: Bool) { // Refresh the table to ensure any data changes are displayed tableVIEw.reloadData() // Delegate the search bar to this table vIEw class searchbar.delegate = self } func searchbarTextDIDEndEditing(searchbar: UISearchbar) { // dismiss the keyboard searchbar.resignFirstResponder() // Force reload of table data self.loadobjects() } func searchbarSearch@R_301_5554@Clicked(searchbar: UISearchbar) { // dismiss the keyboard searchbar.resignFirstResponder() // Force reload of table data self.loadobjects() } func searchbarCancel@R_301_5554@Clicked(searchbar: UISearchbar) { // Clear any search criteria searchbar.text = "" // dismiss the keyboard searchbar.resignFirstResponder() // Force reload of table data self.loadobjects() }}解决方法 将内容模式设置为Aspect Fill,尝试将剪辑设置为true,因为内容模式方面的填充会继续填充图像视图的框架,直到框架完全填满内容,同时保持纵横比不变.在填充具有图像保持宽高比的容器的过程中,垂直或水平框架被完全填充,并且填充继续到另一个(如果水平比垂直或反之亦然)部分被完全填充.因此,垂直或水平方向上的第一个填充部分将超出边界,并且内容将在图像视图的框架外部可见.要剪辑额外的内容,我们需要使用imageVIEw的clipsToBounds属性设置为true来剪切额外的部分
cell.photo.contentMode = UIVIEwContentMode.ScaleAspectFillcell.photo.clipsToBounds = true总结
以上是内存溢出为你收集整理的ios – 为什么缩放比UIImageVIew大小更大的图像? (使用swift)全部内容,希望文章能够帮你解决ios – 为什么缩放比UIImageVIew大小更大的图像? (使用swift)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)