这是我尝试过的,它确实从左边添加了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?全部内容,希望文章能够帮你解决ios – 如何动画UIBarButtonItem从左侧滑动UIToolbar?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)