0
說我有4個圖像,我下載 我想顛倒我所在的圖像的編號。現在圖像開始於4/4,但我希望它讀取1/4。所以基本上我正試圖扭轉數字。這個功能是查找我所在的圖像號碼。所以它越接近最後的圖像,它就把數字變成1.我想要相反的效果。我希望最後一張圖像的編號變成4.所以,如果我向右滑動數字從4/4到3/4到2/4到1/4。但我想第一個圖像是1而不是4,所以它會從1/4到2/4到3/4到4/4。在UIScrollview中顯示我在哪個圖像swift
這裏是我正在做它:
//MARK: Set up and download Promotions
var numberPromotions = 0;
var imageSize = 0;
private var promos = Array<(picture: String, path: String)>()
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("Scroll finished")
print("My promot gus" , self.numberPromotions)
print("Scroll number", scrollView.contentOffset.x)
print("IMAGE size " , self.imageSize)
var myPlace : Double = 0
var totalSize : Double = 0
let scrollviewOffset = Double(scrollView.contentOffset.x)
print("int Scroview " , scrollviewOffset)
totalSize = Double(self.imageSize * (numberPromotions - 1))
print("To;tal size" , totalSize)
if scrollviewOffset == 0 {
myPlace = Double(numberPromotions)
}else
{
myPlace = Double(totalSize/scrollviewOffset)
print("Gus Place" , myPlace)
}
print(myPlace % 1 == 0.5)
if myPlace % 1 == 0.5
{
print("Not a whole number Adding 0.5")
myPlace = myPlace + 0.5
}
print("My place", myPlace)
var myString : String
let myPlaceString = String(Int(myPlace))
myString = myPlaceString + "/" + String(numberPromotions)
numOfPromoLabel.text = myString
}
工作就像一個魅力,我不得不打破它改變它一點點。這太複雜了,無法及時解決。但這個想法很有效。非常感謝你! – MNM