- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我的 iOS 应用程序中,我有一个带有 UIToolbar 控件的媒体播放器。我想让 UIBarButtonItem 在我触摸播放器屏幕时从左侧滑到 UIToolbar 上。
这是我试过的,它确实从左边添加了 UIBarButtonItem,但是没有动画部分。
// create new button
UIBarButtonItem* b = [[UIBarButtonItem alloc] initWithTitle:@"b"
style:UIBarButtonItemStyleBordered
target:self
action:nil];
NSMutableArray* temp = [toolbar.items mutableCopy]; // store the items from UIToolbar
NSMutableArray* newItems = [NSMutableArray arrayWithObject:b]; // add button to be on the left
[newItems addObjectsFromArray:temp]; // add the "old" items
[toolbar setItems:newItems animated:YES];
非常感谢任何形式的帮助!
最佳答案
我有一个类似的问题,设计师想要在导航栏中使用这种动画。
假设您的应用不需要其他按钮移动,那么您可以这样做:
// create a UIButton instead of a toolbar button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"b" forState:UIControlStateNormal];
// Save the items *before* adding to them
NSArray *items = toolbar.items;
// Create a placeholder view to put into the toolbar while animating
UIView *placeholderView = [[UIView alloc] initWithFrame:button.bounds];
placeholderView.backgroundColor = [UIColor clearColor];
[toolbar setItems:[items arrayByAddingObject:[[UIBarButtonItem alloc] initWithCustomView:placeholderView]]
animated:NO];
// get the position that is calculated for the placeholderView which has been added to the toolbar
CGRect finalFrame = [toolbar convertRect:placeholderView.bounds fromView:placeholderView];
button.frame = CGRectMake(-1*button.bounds.size.width, finalFrame.origin.y, button.bounds.size.width, button.bounds.size.height);
[toolbar addSubview:button];
[UIView animateWithDuration:duration
animations:^{ button.frame = finalFrame; }
completion:^(BOOL finished) {
// swap the placeholderView with the button
[toolbar setItems:[items arrayByAddingObject:[[UIBarButtonItem alloc] initWithCustomView:button]]
animated:NO];
}];
如果您的应用确实需要移动其他按钮,那么它会有点棘手 b/c 您必须只使用 customView 栏按钮项目并获取所有按钮的初始位置,拉动它们进入工具栏(并离开项目列表),为它们制作动画,然后将所有内容放回原处。 (简单,对吧?)祝你好运!
关于ios - 如何动画 UIBarButtonItem 从左侧在 UIToolbar 上滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21196255/
我正在创建一个 UIToolbar,上面只放置了一个 UILabel。标签内容是动态的并且可以更改,我想将其集中在 UIToolbar 上。 有人知道 UIToolbar 左侧和右侧的确切边距大小吗?
我正在关注来自 here 的第二条提示.在本技巧中,两个 UIBarButtonItem 被放在一个 UIToolbar 中。最后,将 UIToolbar 添加到 UINavigationBar。现在
我有一个非常顽固的 UIToolbar,无论我尝试如何不同的方法,它都拒绝改变其高度。 我看过这个问题,但它对我不起作用 Is there a way to change the height of
如何制作垂直的 UIToolbar? 最佳答案 子类化 UIToolbar 并执行以下操作: CGFloat DegreesToRadian(CGFloat degrees) { return
是否可以在屏幕顶部放置一个 UIToolbar?示例应用程序类似于“日历”,右侧有“+”,左侧有“日历”按钮。 最佳答案 您可以将 UIToolbar 放置在任何地方。这只是一个 UI View 。
我需要创建一个使用图像作为背景的 UIToolbar 对象。大多数按钮也是图像,并且是矩形的。然而,有一个按钮是圆形的,并且与工具栏重叠,就像 Windows 任务栏上的“开始”按钮一样。见下文。 我
我想显示一个顶部有圆角的UIToolbar,最简单的方法是什么?工具栏未在窗口上对齐;它周围都有边距。谢谢! 最佳答案 非常简单。 首先 - 在 View Controller 的 .h 文件中有一个
我的 View 底部有一个 UIToolbar,并且此工具栏中有一个 UITextField。当我开始编辑此字段时,它隐藏在键盘后面。为了查看我输入的内容,我想在键盘出现时将工具栏向上移动(然后在完成
在我的应用程序中,我有一个工具栏,在某个时刻我想禁用或启用一些按钮。最简单的方法是什么?如何访问 UIToolbar 的 items 属性? 这是我的代码: -(void)addToolbar {
我有一个 UINavigationController,它被推送到 DetailsViewController。在这个DetailsViewController中,我想使用每个UINavigation
昨天下载了 IOS5 SDK,我用来将 UIToolbar 的背景设置为自定义图像的这段代码停止工作。如果我将目标设置为 IOS4.3 及以下,它仍然有效。 [self.bizToolbar inse
我正在尝试放置 UIToolBar在 UINavigationBar . UIToolbar* tempFontSizeToolBar = [[UIToolbar alloc] initWith
我有一个 UItableView,底部有一个工具栏。工具栏有两个按钮,分别是“水果”和“蔬菜”。单击它们将仅显示相应的类别。 我已经设法让显示功能正常工作,但我不知道如何在选择时将按钮设置为 sele
这个问题在这里已经有了答案: How to create this toolbar programmatically [closed] (6 个答案) 关闭 8 年前。 我试图在一个子类 ABPer
我想创建上面的用户界面。具体来说,一个更高的工具栏。但我需要以底层 UI(即内容 View )相应显示(即在工具栏下方)的方式这样做。 我熟悉 iOS 5 中新的 UIAppearance 选项。但是
UI问题在这里;我认为 UIToolbars 应该与状态栏融为一体?还是仅适用于 NavigationControllers? 最佳答案 UIToolBar 在顶部有一条默认的 1px 线(超出范围)
我有一个 UIToolbar。 如果我像这样创建一个 UIBarButton,它会起作用: UIBarButtonItem *button = [[UIBarButtonItem alloc] ini
我希望在用户单击按钮时(在我的例子中是当他们放大照片时)以编程方式将 UIToolbar 添加到 View 。 当我在 click 方法中创建工具栏并添加到 subview 时,它似乎工作正常但是如果
我的 View 上有一个 UITextView,并且可以通过按键盘工具栏上的完成按钮来关闭键盘。此按钮还对文本执行保存。在我的应用程序的最新版本之前,整个事情都运行得很好。我不明白发生了什么事。我怀疑
嘿伙计们,我正在尝试向 UIToolbar 添加文本,但有一个问题:我想更改字体并有 2 行文本(顶行较小,底行较大)。有什么想法如何做到这一点吗? 提前致谢! 最佳答案 您需要创建一个包含自定义 V
我是一名优秀的程序员,十分优秀!