Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: subviews with centeroffset (hence not crosshair!!) ignored while zooming in/out the parent view
    primarykey
    data
    text
    <p>I have:</p> <ul> <li>an <code>UIScrollView</code><br></li> <li><p><code>UIImageView</code> as subview of the previous scrollview (it's a very big background image with 1 green circle and 1 red circle). It has 2 two subviews:</p> <ol> <li>first pin image (a white cross)</li> <li>second pin image (an orange custom map pin) </li> </ol></li> </ul> <p>Both pins have to point to the center of their circles:</p> <ul> <li>the center of the white cross must be on the center of the green circle <li>the bottom peak of the orange map-pin must be on the center of the red circle. </ul> <p>This is the desired behavior and, when the App start, I got it. <br> (I have also successfully apply inverted transform to prevent both pins from scaling with the big background image while zooming (as explained by Andrew Madsen in another post). <br><br> <strong>The problem</strong><br> When I zoom in/out, <strong>orange pin</strong> (which have a kind of "centerOffset") seems move up/down because <strong>its bottom peak</strong> lost the center of red circle.<br> (while white cross is ok because it is always centered with the circle)</p> <p>See 1 example of correct behavior (at launch) and 2 examples of wrong behavior here: <a href="https://www.dropbox.com/s/8stjh892wm8yfdb/123.png" rel="nofollow">https://www.dropbox.com/s/8stjh892wm8yfdb/123.png</a></p> <p>I've also try to subclass a MKAnnotationView for the orange pin, and set centerOffset:<br> </p> <pre><code>self.centerOffset = CGPointMake(0,-self.image.size.width/2); </code></pre> <p>in <br> <code>- (void)setAnnotation:(id &lt;MKAnnotation&gt;)annotation</code>, <br>but it is ignored (maybe because it's not on a mkmapview).<br></p> <p><br></p> <p>How can I set the bottom peak of orange pin to follow the center of red circle while zooming in/out? <br><br>I repeat it for clarify: I don't want that the <strong>center</strong> of orange pin be always on the center of red circle, I want that the <strong>bottom peak</strong> of the orange pin be always on the center of red circle. <br></p> <p>Here is sample code of the ViewController<br></p> <pre><code>#import &lt;QuartzCore/QuartzCore.h&gt; #import "TestViewController.h" @implementation TestViewController @synthesize scrollView; //SLImageView is my extension of UIImageView with the invertedTransform (see: http://stackoverflow.com/questions/12981201/keep-subviews-of-uiscrollview-from-resizing) @synthesize backgroundImageView; - (void)viewDidLoad { [super viewDidLoad]; UIImage *image = [UIImage imageNamed:@"circles.png"]; self.backgroundImageView = [[SLImageView alloc] initWithImage:image]; self.backgroundImageView.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.size}; [self.scrollView addSubview:self.backgroundImageView]; // Tell the scroll view the size of the contents self.scrollView.contentSize = image.size; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Set up the minimum &amp; maximum zoom scales CGRect scrollViewFrame = self.scrollView.frame; CGFloat scaleWidth = scrollViewFrame.size.width / self.scrollView.contentSize.width; CGFloat scaleHeight = scrollViewFrame.size.height / self.scrollView.contentSize.height; CGFloat minScale = MIN(scaleWidth, scaleHeight); self.scrollView.minimumZoomScale = minScale; self.scrollView.maximumZoomScale = 4.0f; self.scrollView.delegate = self; UIImageView *topWhiteCrossPin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cross.png"]]; topWhiteCrossPin.center = CGPointMake(110, 304); UIImageView *topOrangeMapPin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"centerOffsetPin.png"]]; topOrangeMapPin.center = CGPointMake(284, 288); [backgroundImageView addSubview:topWhiteCrossPin]; [backgroundImageView addSubview:topOrangeMapPin]; self.scrollView.zoomScale = minScale * 3.5; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return backgroundImageView; } @end </code></pre> <p>Complete example xcode project here: <a href="https://www.dropbox.com/s/rvohsn1wemd4lyj/AffineTransformExample.zip" rel="nofollow">https://www.dropbox.com/s/rvohsn1wemd4lyj/AffineTransformExample.zip</a></p> <p>Thanks in advance.<br> Mick</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload