【问题标题】:How to mark the UIToolBar autoresze when it rotated旋转时如何标记 UIToolBar 自动调整大小
【发布时间】:2012-05-09 15:19:43
【问题描述】:

我创建了一个工具栏。就像这样:

    UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, toolBarHeight)];

    toolbar.autoresizingMask=UIViewAutoresizingFlexibleWidth;
    UIBarButtonItem *itemNull=[[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
    UIBarButtonItem *item0=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item1=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item2=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pre)] autorelease];
    UIBarButtonItem *item3=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(pre)] 
        autorelease];
    UIBarButtonItem *item4=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pre)] autorelease];
    itemNull.width=frame.size.width-itemwidth*5;
    item0.width=itemwidth;
    item1.width=itemwidth;
    item3.width=itemwidth;
    item4.width=itemwidth;
    item2.width=itemwidth;

    [toolbar setItems:[NSArray arrayWithObjects: itemNull,item0,item1,item2,item3,item4, nil]];
    [self addSubview:toolbar];
    [toolbar release];

它被添加到视图中。但是当我旋转视图时,这些项目不在标志上。 我想知道如何让它可见而不是重置它的框架。 这些项目是否具有 autoresize 之类的属性?

【问题讨论】:

标签: objective-c ios toolbar autoresize


【解决方案1】:

有一个内置的隐藏工具栏..

[self.navigationController setToolbarHidden:NO animated:YES]; // i hope its a navigation based application.

修改代码

UIBarButtonItem *itemNull=[[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
UIBarButtonItem *item0=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item1=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item2=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pre)] autorelease];
UIBarButtonItem *item3=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(pre)] 
    autorelease];
UIBarButtonItem *item4=[[[UIBarButtonItem  alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pre)] autorelease];
[self.navigationController setToolbarHidden:NO animated:YES];
self.toolbarItems = [NSArray arrayWithObjects: itemNull, item0, item1, item2, item3, item4, nil];

希望对您有所帮助。快乐编码:)

【讨论】:

  • 它取消隐藏已经可用的工具栏。 [self.navigationController setToolbarHidden:NO 动画:YES];将显示工具栏。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多