0
A
回答
1
在button
點擊事件,只需根據您的要求動畫imageView
的x coordinate of origin
。
實施例:
@IBAction func onTapButton(_ sender: UIButton)
{
if sender.isSelected
{
UIView.animate(withDuration: 2.0, animations: {
self.imageView.frame.origin.x = 0.0
})
}
else
{
UIView.animate(withDuration: 2.0, animations: {
self.imageView.frame.origin.x = UIScreen.main.bounds.width
})
}
sender.isSelected = !sender.isSelected
}
上面的代碼將如下工作:
時
selecting
button
,imageView's
x coordinate of origin
被移動到屏幕(UIScreen.main.bounds.width
)- 的
extreme right
當
de-selecting
button
,imageView's
x coordinate of origin
移動到屏幕(0.0
)
0
使用此代碼移動左手
func moveToLeft()
{
var frame = imageView.frame
frame.origin.x = -imageView.frame.size.width //Adjust this value according to your need
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: {() -> Void in
self.imageView.frame = frame
}, completion: {(_ finished: Bool) -> Void in
/*done*/
})
}
使用此代碼移動右
func moveToRight()
{
var frame = imageView.frame
frame.origin.x = 0 //Adjust this value according to your need
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: {() -> Void in
self.imageView.frame = frame
}, completion: {(_ finished: Bool) -> Void in
/*done*/
})
}
相關問題
- 1. 當點擊它時動畫像按鈕
- 2. 當我點擊按鈕java
- 3. 當我點擊按鈕
- 4. 當按鈕被點擊時我怎樣才能得到?
- 5. 如何隱藏按鈕圖像,當我點擊按鈕,ios
- 6. 當我點擊一個按鈕時,重新啓動動畫
- 7. 當點擊按鈕時更改屏幕
- 8. 顯示,當點擊按鈕
- 9. 當點擊按鈕
- 10. 當點擊按鈕
- 11. 當我點擊另一個按鈕時,無法停止按鈕點擊事件
- 12. 當我點擊刷新按鈕時,圖像從不出現
- 13. 點擊按鈕一次顯示UIImage。再次點擊按鈕隱藏UIImage
- 14. 當點擊按鈕時不顯示Alertdialog
- 15. 當點擊按鈕時顯示AlertDialog
- 16. 按鈕點擊許多按鈕動畫
- 17. 當我點擊一個按鈕時,爲什麼會出現相同的按鈕?
- 18. 如何隱藏按鈕,當我點擊按鈕來顯示內容?
- 19. 當按鈕被點擊時,在按鈕附近隱藏div
- 20. 點擊時顯示/隱藏按鈕
- 21. 我怎樣才能讓HTML元素被JavaScript隱藏,並且當我點擊一個按鈕時顯示出來?
- 22. javascript:點擊按鈕時移動圖像
- 23. 當我點擊按鈕時,jQuery模式將不會顯示
- 24. 當我點擊按鈕時,如何自動滾動到div?
- 25. 調用C#代碼隱藏功能,當我點擊按鈕時div會顯示
- 26. 當我點擊一個按鈕的listview另一個按鈕也點擊我怎麼能阻止它
- 27. 當我們在位置1點擊ListView按鈕時,第10個位置的按鈕也被點擊
- 28. 當我點擊另一個按鈕時,如何在JavaScript中隱藏按鈕
- 29. 畫廊滾動時點擊按鈕?
- 30. 爲什麼當我點擊我的按鈕時,我不確定?
請出示一些代碼的
extreme left
,你嘗試過什麼? – 3stud1ant3使用塊將圖像添加到uiview並使uiview動畫。你可以玩你想要的應用程序中的動畫 – cole