我正在写一个应用程序在Xcode中,我有一个按钮,当按下更改颜色。我想在按下时将按钮翻转并改变其颜色,例如从红色变为绿色。我会如何去做这件事?触摸UIButton触摸
回答
最简单的方法是使用过渡动画。
[UIView beginAnimations:nil context:nil];
// self.b is a UIButton; _red is a BOOL ivar
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.b cache:YES];
[self.b setBackgroundColor:(_red ? [UIColor greenColor] : [UIColor redColor])];
_red = !_red;
[UIView commitAnimations];
您必须修复该代码才能更改与您真正想要更改的按钮有关的任何内容;它可能不是背景颜色。
谢谢,我得到它的工作 – Actionman
@马特解夫特#
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromLeft, forView: self.myButton, cache: true)
self.myButton.backgroundColor = myBOOL ? UIColor.greenColor() : UIColor.redColor()
self.myButton.setTitleColor(myBOOL ? UIColor.redColor() : UIColor.greenColor(), forState: UIControlState.Normal)
myBOOL = !myBOOL
UIView.commitAnimations()
虽然这可能在理论上回答这个问题,[这将是更可取的](/ meta.stackoverflow.com/q/8259)包括答案的基本部分在这里,并提供链接以供参考。 –
@BhargavRao完成:) –
谢谢你的 –
- 1. 取消触摸它时的UIButton触摸
- 2. 检测触摸UIButton
- 3. UIButton触摸事件
- 4. UIButton不闪烁在触摸
- 5. UIButton的可触摸区域
- 6. UIButton触摸事件重叠
- 7. IOS的UIButton触摸取消
- 8. UIButton TouchUpInside触摸位置
- 9. UIButton未注册触摸
- 10. 触摸时淡出UIButton
- 11. UIButton移动和触摸
- 12. UIButton触摸并保持
- 13. UIButton不响应触摸
- 14. 我无法触摸的UIButton
- 15. 触摸移动时取消触摸UIButton(iOS)
- 16. UIButton同时触摸内部和触摸重复?
- 17. 的UIButton有两个状态 - 触摸和长触摸
- 18. 如何在触摸UIButton时通过UIView检测触摸?
- 19. 触摸时更大触摸
- 20. 触摸
- 21. 触摸
- 22. 触摸
- 23. 触摸开始与多点触摸让
- 24. 触摸和触摸之间的时间
- 25. 可可触摸:动画上的触摸
- 26. 事件触摸屏轻轻触摸
- 27. 当我触摸TextView时触摸按钮
- 28. 可可触摸 - 在UIImageView中触摸
- 29. XCode - touchBegan - 最近触摸/新触摸
- 30. 触摸后如何检测触摸
谷歌 “'UIView'块动画” 和 “'CGAffineTransform'参考”。 – 2014-02-11 00:07:57