Reputation: 845
I am creating an UIToolBar via Interface Builder. I set it as an IBOutlet.
Within the viewDidLoad
of my viewController
I am trying to set the frame.
What I want to achieve is modify the position of it so it can be animated.
But nothing happens.
Is there a different way to do that?
Thanks
myOwnToolBar.frame = CGRectMake(0, 0, 100, 55);
[self.view addSubview:myOwnToolBar];
Upvotes: 2
Views: 4252
Reputation: 131
Little hack with swift 3:
override func viewDidLoad() {
super.viewDidLoad()
UIView.animate(withDuration: 0.3) {
self.navigationController?.toolbar?.transform = CGAffineTransform(translationX: 0, y: -216)
}
}
Objective-c example:
- (void)viewDidLoad {
[super viewDidLoad];
[UIView animateWithDuration:0.3 animations:^{
self.navigationController.toolbar.transform = CGAffineTransformMakeTranslation(0, -216);
}];
}
Set your variables or constants for animation duration, x-offset or y-offset
Upvotes: 0
Reputation: 130202
If you are trying to create a UIToolBar
programmatically, you can't just set a frame without allocating and initializing the toolBar. Try this:
myOwnToolBar = [[UIToolBar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[self.view addSubview:myOwnToolBar];
When you create an IBOutlet, an alloc/init call is implied. You just need to keep in mind that this is not true for objects created in code.
Upvotes: 3