I’m designing a game that has a large hex style map in a UIScrollView and a 1/10th scale “mini map” in another view. The mini map has a rectile that is used to indicate the current area visible in the scroll view. What’s the best way to position the rectile to synchronize it with the main map?
Share
You can get your UIScrollView’s
contentOffsetwhenever you’d like. You could check this value in the UIScrollView delegate method- (void)scrollViewDidScroll:(UIScrollView *)scrollView. Once you have the contentOffset you should divide that by your UIScrollView’scontentSizeminus it’sframe.size. That gives you a float, that float can then be used to determine the positioning of the rectile in the smaller view. Some code below to show what I’m talking about. I’m just going to give you the x positioning example. rinse and repeat for y positioning.The
xRatis the percentage (in float format) that the scroll view has scrolled. So just use xRat to position the rectile along the x-axis by that percentage.