0

I have a scroll view added as a sub view with a height of approx. 500.

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(x,y,500,300)];
[self.view addSubView:scrollView];

Now I have another view say View1 which contains a lot of buttons arranged in a vertical direction. View1's height is approx. twice the height of my scrollView.

View1 = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,300)];
[scrollView addSubView: View1];

now I set my scrollView's content size to fit in my View1.

[scrollView setContentSize: CGSizeMake(1000,300)];

Now able to scroll through my View1 completely. Now I need to show a popUpViewController when a button within my View1 is pressed with a direction up or down depending upon the button's current location. For example if the button lies below the half way in my scrollView's frame, the popOverViewController should pop up with an upward direction.

Now how do I get relative coordinates of the button to scroll View frame, and if that button had an initial position below my scrollView's frame.height.y/2 and after scrolling the button moved up say to a position above my scrollView's frame.height.y/2, how do you get the relative coordinates then. I have tried the convertRect: toView: but no success.

I hope you guys understand what i am trying to say here.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
Junaid Ahmed
  • 175
  • 1
  • 9

1 Answers1

0

Use the presentPopoverFromRect:inView:permittedArrowDirections:animated: method to present a UIPopoverController, anchored to (arrow points to) a particular view.

To anchor the popover to a bar button, use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:.

You can let iOS automatically figure out the arrow direction.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • correct but for example the button before scrolling was in the bottom half of the scroll view. Now a direction up is suitable here. After scrolling that same button is in the top half of the scroll view frame, now i want use the direction down popover. I need to get the relative position so i can work out what direction to use in the popover – Junaid Ahmed Aug 20 '13 at 17:25
  • @user1235151, in most cases, you can let iOS figure out the arrow direction. – Marcus Adams Aug 20 '13 at 17:28