iOS 中按钮(装扮成卡片)的翻转效果

发布于 2024-12-25 17:09:49 字数 1557 浏览 0 评论 0原文

更新:

到目前为止,我遇到的问题是我必须触摸卡片两次才能让它们在加载时翻转。第一次翻转后,它们会按预期打开触摸,但第一次卡片需要两次触摸才能初始状态改变。

这是一个小视频,展示了我刚刚解释的行为: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眸 2025-01-01 17:09:49

欢迎来到 StackOverflow!

您可以使用 UIView 执行的操作也可以使用 UIButton 执行,因为它们也是 UIView 的后代。因此,您的转换代码应该只需很少的调整即可工作。

Welcome to StackOverflow!

What you can do with UIViews can also be done with UIButtons, since they are descendants of UIViews too. So your transition code should work with very little adaptation needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文