Reputation: 2221
I have a set of uibuttons inside a scrollview which I use for navigation. I've added effects to these buttons to slide to center and resize when they are tapped like so:
-(void)slideButtons:(int)selectedId forType:(NSString *)btnType {
if([btnType isEqualToString: @"somestring"]) {
if(selectedId == 1) {
//set the position to slide the button to
} else { //other positions for other id }
}
myButton.frame = CGRectMake(myButton.frame.origin.x,40,70,40);
[myScrollView setContentOffset:CGPointMake(pos, 40) animated: YES];
}
My buttons' size and positions are (70,35) and (0,45) respectively. While the scrollview's size and position are (320, 40) and (0, 0) respectively. Now, when I go to another view controller (using segue) then pop back to this view, the buttons disappear and would reappear after I swipe the content. The buttons also disappear whenever I try to swipe the scrollview itself. I did not add any code to hide it. Why is this happening? How can I handle it? please help.
I'm not sure if this helps but I've disabled autolayout to make changes to the view then enabled it again with still the same problems.
Upvotes: 0
Views: 124
Reputation: 222
try to use instead of
[myScrollView setContentOffset:CGPointMake(pos, 40) animated: YES];
this:
myScrollView scrollRectToVisible:myButton.frame animated:YES];
Upvotes: 0
Reputation: 104082
This is probably an auto layout problem. If that's turned on (which it is by default), then you shouldn't directly change any frames, but do any moving or resizing with constraints. Either turn off auto layout, or use it to slide your buttons.
Upvotes: 1