Since horizontal 'scrolling' is only allowed when a button is tapped, then set the UIScrollView
contentSize
width to the width of the screen and its height as appropriate. For 'scrolling' horizontally on button taps, just animate the moving of a view horizontally.
The view hierarchy would be something like an outerView
that is the width and height of what you are setting your UIScrollView contentSize
to currently. Your scroll view is a subview of the outerView
and the toolbar is a subview of the scroll view.
To animate the horizontal movement, it is typically easiest to change the outerView.center
and the toolbarView.center
, something like:
CGPoint newCenterPoint; CGPoint newToolbarCenterPoint; CGPoint centerPoint1 = // set center as appropriate CGPoint centerPoint2 = // set center as appropriate CGPoint centerPoint3 = // set center as appropriate CGPoint toolbarCenter1 = // set center as appropriate CGPoint toolbarCenter2 = // set center as appropriate CGPoint toolbarCenter3 = // set center as appropriate if (buttonTapped == button1) { newCenterPoint = centerPoint1; newToolbarCenterPoint = toolbarCenter1; } else if (buttonTapped == button2){ newCenterPoint = centerPoint2; newToolbarCenterPoint = toolbarCenter2; } else if (buttonTapped == button3){ newCenterPoint = centerPoint3; newToolbarCenterPoint = toolbarCenter3; } [UIView animateWithDuration:0.25 animations:^{ outerView.center = newCenterPoint; toolbarView.center = newToolbarCenterPoint; }];