iPhone右转按钮(如iTunes) [英] iPhone flip right button (like iTunes)

查看:149
本文介绍了iPhone右转按钮(如iTunes)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个视图之间切换。这很容易,代码在下面,但我也想同时翻转用于执行翻转的按钮。

I'm trying to flip between two views. That's easy, the code is below, but I also want to simultaneously flip the button used to perform the flip.

你可以在iPod应用程序中看到这种行为重新播放曲目;点击翻盖按钮会在封面图片和曲目列表之间翻转,但它会同时翻转按钮。

You can see this behavior in the iPod application when you're playing a track; tapping the flip button flips between the cover art and the track listing, but it flips the button at the same time.

这是导航控制器上的一个页面,我要翻转的按钮是 rightBarButtonItem

This is a page on the navigation controller, and the button I want to flip is the rightBarButtonItem.

这是我到目前为止的代码。这会翻转视图,但不会翻转右边的BarButton。

Here's the code I have so far. This flips the view, but not the rightBarButton.

[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
showingBackside = !showingBackside;
if (showingBackside) {
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft
                           forView: self.view
                             cache: YES];
    [self.view addSubview: backside.view];
    [frontside.view removeFromSuperview];
} else {
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
                           forView: self.view
                             cache: YES];
    [self.view addSubview: frontside.view];
    [backside.view removeFromSuperview];
}
// flip image, too
NSString *newImage = showingBackside ? @"backside.png" : @"frontside.png";
[(self.navigationItem.rightBarButtonItem) setImage: [UIImage imageNamed: newImage]];
[UIView commitAnimations];

(此处的图片翻转代码可能无法编译;我之后添加了它以尝试解释我的内容尝试这样做。)

(The image flipping code here may not compile; I added it after to try to explain what I was trying to do.)

我遇到麻烦的地方是我想改变导航控制器中最右边的按钮,以便它同时翻转。

Where I'm running into trouble is I want to change the rightmost button in the navigation controller so it flips simultaneously.

我该怎么做?我的动画是什么视图,我是作为同一动画块的一部分还是作为单独的动画块执行的?任何提示都会受到赞赏,我肯定还没有很好的处理动画。

How do I do this? What view do I animate, and do I do it as part of the same animation block or as a separate one? Any tips would be appreciated, I definitely don't have a good handle on animation yet.

推荐答案

有一些讨论这里,但解决方案并不那么优雅。

There's some discussion here, but the solution is not so elegant.

首先,由于 UIBarButtonItem 不是 UIView 的后代,你可能无法使用UIKit动画直接在 UIBarButtonItem 上。但是,您可以尝试设置 customView 并为其设置动画。您可以使用相同的动画块。

First of all, since UIBarButtonItem is not a descendant of UIView, you probably cannot use UIKit animations directly on the UIBarButtonItem. However, you can try setting a customView and animating that. You can use the same animation block.

这篇关于iPhone右转按钮(如iTunes)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆