iOS 中按钮(装扮成卡片)的翻转效果
更新:
到目前为止,我遇到的问题是我必须触摸卡片两次才能让它们在加载时翻转。第一次翻转后,它们会按预期打开触摸,但第一次卡片需要两次触摸才能初始状态改变。
这是一个小视频,展示了我刚刚解释的行为: http://youtu.be/KrCmfyK3Z9Q?hd= 1
代码非常简单。它是这样的:
viwDidLoad 上的初始化:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:optionOneBack];
[self.view addSubview:optionTwoBack];
[self.view addSubview:optionThreeBack];
}
翻转方法:
- (void)flip:(id)sender {
// Identify the card that has been touched (button clicked) and assign the values for the animation
if ((sender == optionOneFront) || (sender == optionOneBack)){
front = optionOneFront;
back = optionOneBack;
}
else if ((sender == optionTwoFront) || (sender == optionTwoBack)){
front = optionTwoFront;
back = optionTwoBack;
}
else {
front = optionThreeFront;
back = optionThreeBack;
}
// Flip the card with animation
BOOL optionFrontIsHidden = front.hidden;
UIView *transitionView;
transitionView = optionFrontIsHidden ? back : front;
[UIView transitionWithView:transitionView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:^(BOOL finished){
front.hidden = !optionFrontIsHidden;
back.hidden = optionFrontIsHidden;
}
];
}
在我继续谷歌搜索时您可以提供的任何帮助将不胜感激。
预先感谢,
胡安。
UPDATE:
The problem I have so far is that I have to touch the cards two times for them to flip on load. After they've flipped the first time they would turn on touch as expected, but that first time the cards need two touches to the initial change of state.
Here's a little video to show the behavior I have just explained: http://youtu.be/KrCmfyK3Z9Q?hd=1
The code is pretty simple. It goes like this:
Initialization on viwDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:optionOneBack];
[self.view addSubview:optionTwoBack];
[self.view addSubview:optionThreeBack];
}
Flip method:
- (void)flip:(id)sender {
// Identify the card that has been touched (button clicked) and assign the values for the animation
if ((sender == optionOneFront) || (sender == optionOneBack)){
front = optionOneFront;
back = optionOneBack;
}
else if ((sender == optionTwoFront) || (sender == optionTwoBack)){
front = optionTwoFront;
back = optionTwoBack;
}
else {
front = optionThreeFront;
back = optionThreeBack;
}
// Flip the card with animation
BOOL optionFrontIsHidden = front.hidden;
UIView *transitionView;
transitionView = optionFrontIsHidden ? back : front;
[UIView transitionWithView:transitionView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:^(BOOL finished){
front.hidden = !optionFrontIsHidden;
back.hidden = optionFrontIsHidden;
}
];
}
Any help you can provide while I continue my googling would be greatly appreciated.
Thanks in advanced,
Juan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到 StackOverflow!
您可以使用
UIView
执行的操作也可以使用UIButton
执行,因为它们也是UIView
的后代。因此,您的转换代码应该只需很少的调整即可工作。Welcome to StackOverflow!
What you can do with
UIView
s can also be done withUIButton
s, since they are descendants ofUIView
s too. So your transition code should work with very little adaptation needed.