2017-09-06 37 views
0
import UIKit 

class SalamView: UIView { 

    @IBOutlet var salamView: UIView! 

    @IBOutlet weak var salamLogoIMG: UIImageView! 

    var salamLogoImgOrigY: CGFloat! 
    var salamLogoImgFromToY: CGFloat! 

    override init(frame: CGRect) { 
     super.init(frame: frame) 
     initializeViews() 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
     initializeViews() 
    } 

    private func initializeViews(){ 
     Bundle.main.loadNibNamed("SalamView", owner: self) 
     salamView.clipsToBounds = true 
     salamView.setHeight(height: screenSize.height - statusBarHeight) 
     salamView.setWidth(width: screenSize.width) 
     addSubview(salamView) 

     salamLogoImgOrigY = salamLogoIMG.frame.origin.y 
     salamLogoImgFromToY = -(salamLogoIMG.frame.size.height + salamLogoImgOrigY) 

     salamLogoIMG.frame = CGRect(x: salamLogoIMG.frame.origin.x, 
y: salamLogoImgFromToY, 
width: salamLogoIMG.frame.size.width, 
height: salamLogoIMG.frame.size.height) 
    } 

} 

我需要改變salamLogoIMG的y位置,以salamLogoImgFromToY,如果BTN行動工作運行新的職位代碼行,但我需要在第一次設置,請大家幫忙我如何設置新y位置的ImageView在迅速UIView類

+0

如果您想第一次設置它,爲什麼不從故事板中設置它? –

回答

0

嘗試設置你的框架中layoutsubviews方法您UIView

+0

dosn't在layoutSubviews中工作 –

1

療法是問題

salamLogoImgFromToY = - (salamLogoIMG.frame.size.height + salamLogoImgOrigY) salamLogoImgFromToY never( - )減號