Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在初始视图控制器上以编程方式绘制UIImageView边界';s实例化_Ios_Swift_Uiimageview_Uicollectionviewcell_Xcode6.4 - Fatal编程技术网

Ios 在初始视图控制器上以编程方式绘制UIImageView边界';s实例化

Ios 在初始视图控制器上以编程方式绘制UIImageView边界';s实例化,ios,swift,uiimageview,uicollectionviewcell,xcode6.4,Ios,Swift,Uiimageview,Uicollectionviewcell,Xcode6.4,我在.xib文件中有一个UIImageView,当用户选择集合视图单元格时,需要更改其大小。.xib文件被加载到视图控制器中,并有一个IBOutlet连接这两个文件。当前的方法我在UIView中工作得很好,但在UIImageView中失败 该代码仅在第一次加载屏幕时失败。如果用户选择任何集合视图单元格,UIImageView将正常更新 func displayDataForCell(index: Int) { // Set the box fill amount for Anode, Feede

我在.xib文件中有一个UIImageView,当用户选择集合视图单元格时,需要更改其大小。.xib文件被加载到视图控制器中,并有一个IBOutlet连接这两个文件。当前的方法我在UIView中工作得很好,但在UIImageView中失败

该代码仅在第一次加载屏幕时失败。如果用户选择任何集合视图单元格,UIImageView将正常更新

func displayDataForCell(index: Int) {
// Set the box fill amount for Anode, Feeder, and Wave
    let anodePercentAmount = Double(pot.anode!)/100
    let feederPercentAmount = Double(pot.feeder!)/100
    let wavePercentAmount = Double(pot.wave!)/100
    dataView.anodeBoxFill.frame = CGRect(x: 0.0, y: 180.0, width: 120.0, height: 0.0)
    dataView.waveBoxFill.frame = CGRect(x: 0.0, y: 180.0, width: 120.0, height: 0.0)
    dataView.feederBoxFill.frame = CGRect(x: 0.0, y: 180.0, width: 120.0, height: 0.0)

    UIView.animateWithDuration(0.5, animations: { () -> Void in
        self.dataView.anodeBoxFill.frame = CGRect(x: 0.0, y: (180.0 - (180.0*anodePercentAmount)), width: 120.0, height: (180.0*anodePercentAmount))
        self.dataView.feederBoxFill.frame = CGRect(x: 0.0, y: (180.0 - (180.0*feederPercentAmount)), width: 120.0, height: (180.0*feederPercentAmount))
        self.dataView.waveBoxFill.frame = CGRect(x: 0.0, y: (180.0 - (180.0*wavePercentAmount)), width: 120.0, height: (180.0*wavePercentAmount))
    })
}
我在函数
collectionView(\uDidSelectItemAtIndexPath indexPath:\uDidSelectItemAtIndexPath:)中调用上述方法,如下所示:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    // This makes sure only one cell can be selected at once
    if currentPotIndex != indexPath.row {
        let cell = collectionView.cellForItemAtIndexPath(indexPath)
        cell?.highlighted

        let cell0 = collectionView.cellForItemAtIndexPath(NSIndexPath(forItem: currentPotIndex, inSection: 0))
        cell0?.highlighted = false
    }

    self.currentPotIndex = indexPath.row

    displayDataForCell(currentPotIndex)

    bottomCollection.reloadData()

}
最后,这是我目前尝试的解决方案:在
viewDidLoad()
函数中包含
didSelectItemAtIndexPath
函数调用

//Initialize the view with the 0th indexed pot's data
    collectionView(collectionView, didSelectItemAtIndexPath: NSIndexPath(forItem: currentPotIndex, inSection: 0))
    self.dataView.layoutIfNeeded()
我会附上一个图像,但我没有足够的代表。
谢谢你的关注

以下是我为解决这个问题所做的:

重写函数
viewdide(动画:Bool)

并将设置UIImageView动画的行为放入此函数中。我想这是因为无约束图像是在处理其superview中的大小和位置的函数之后加载的。

以下是我为解决此问题所做的操作:

重写函数
viewdide(动画:Bool)

并将设置UIImageView动画的行为放入此函数中。我想这是因为无约束图像是在处理其在superview中的大小和位置的函数之后加载的。

如果不设置动画,它的大小是否正确?@GregPrice它不不幸。如果不设置动画,它的大小是否正确?@GregPrice它不不幸。