Question

I found a lot of discussion, but anyonw work fine for me. I create a toolBar in a viewcontroller :

UIToolbar *toolBar =[[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];

[toolBar setTranslucent:YES];

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *buttonfb = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fb.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(condividiFB)];
UIBarButtonItem *buttontw = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"twitter.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(condividiTW)];

NSArray *toolbaritems = [NSArray arrayWithObjects:flexibleSpace, buttonfb,flexibleSpace, buttontw,flexibleSpace, nil];
toolBar.items = toolbaritems;

[self.view addSubview:toolBar];

it's OK. the toolbar appers very cute, but i want hide or move it during a scroll. i detect the scroll and call a method with the follow solution but doen't work. when i try to hide the toolbar, neither. i try with a lot of solution that i toke here. for esample :

[self.toolBar removeFromSuperview];

but nothing; another way:

[_toolBar setHidden:YES];

neither;

try to move:

self.toolBar.frame = CGRectMake(self.toolBar.frame.origin.x, self.toolBar.frame.origin.y + 100, self.toolBar.frame.size.width, self.toolBar.frame.size.height);

nothing works. I'm gettin crazy.

Was it helpful?

Solution

Set the toolbar up with the property you defined rather than the locally scoped variable in your example.

Change this:

UIToolbar * toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];

To this:

self.toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,[[UIScreen mainScreen]bounds].size.height - 49,[[UIScreen mainScreen] bounds].size.width, 49)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top