You set the position of rect2 y to the value [toolbar frame].origin.y , which at this point in the code is either nil or points to some other instance of the toolbar, because immediately after that alloc and init new toolbar.
Even if the toolbar was valid when setting the frame, you cannot use its current y value as the new y value, because it will be 0 .
You should place it relative to the bottom of the screen, minus the height of the toolbar. Try instead:
CGRect frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 44, [[UIScreen mainScreen] bounds].size.width, 44);
source share