Set up a UIScrollView
of height 1400 with numerous UIButtons
. On clicking each of these UIButtons
, i reveal a small UIView
(hidden when view is loaded) containing some values. I want to display these UIViews
at the center of the displayed area of the UIScrollView
.
When i click 'TYPE'(behind the UIView in the image), i reveal the view as shown below:
But no matter where 'TYPE' button is and when clicked i want to reveal UIView
as shown below(always at the center of the displayed area):
Thanks!
Try this
yourCustomAlert.center = self.view.center;
Inside your scrollView
first get visible Rect of scrollview
CGRect visibleRect = CGRectMake(myScrollView.contentOffset.x, myScrollView.contentOffset.y, myScrollView.bounds.size.width, myScrollView.bounds.size.height)
then get it's center
CGPoint centerPoint = CGPointMake(visibleRect.size.width/2, visibleRect.size.height/2);
then set your alertView's center
yourCustomAlert.center = centerPoint;
Your problem is not clear as much. Though, if you want that your hidden view will appear on the center of the screen despite of the scrollView bounds, you can use
yourHiddenView.center = self.view.center; //If Parent class is a ViewController
//yourHiddenView.hidden = NO;
OR
yourHiddenView.center = self.center; //If Parent class is a UIView
//yourHiddenView.hidden = NO;
And, if you want the hidden view to be at the center of ScrollView
find the visible rect of the scrollView
and find its center
CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.bounds.size;
CGPoint scrollViewCenter = CGPointMake(visibleRect.size.width/2, visibleRect.size.height/2);
yourHiddenView.center = scrollViewCenter;
//yourHiddenView.hidden = NO;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With