I am trying to use the animation from this library: https://github.com/shu223/PulsingHalo
I have a UIScrollView, and within it a UIImageView that has a larger width
UIScrollView *scrollView;
scrollView = [[UIScrollView alloc] init];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.delegate = self;
self.scrollView = scrollView;
[self.view insertSubview:scrollView belowSubview:self.optionsButton];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
imageView = [[UIImageView alloc] init];
self.mapImageView = imageView;
UIImage* mapImg = [UIImage imageNamed:@"..."];
// Add image (larger than screen size) to the image view.
[imageView setImage: mapImg];
// Set the constraints for the scroll view and the image view.
NSDictionary* viewsDictionary = NSDictionaryOfVariableBindings(scrollView, imageView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]|" options:0 metrics: 0 views:viewsDictionary]];
After this, I add a bunch of buttons to my scrollview, programmatically. For instance:
UIButton* flagButton = [UIButton new];
[self.scrollView addSubview: flagButton];
flagButton.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint* xc = [NSLayoutConstraint constraintWithItem:flagButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mapImageView attribute:NSLayoutAttributeLeft multiplier:1.f constant:x];
NSLayoutConstraint* yc = [NSLayoutConstraint constraintWithItem:flagButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mapImageView attribute:NSLayoutAttributeTop multiplier:1.f constant:y];
[self.view addConstraints@[xc, yc]];
Now I want to create my halo for this button. I create a specific view for it, centered around my button. I still haven't quite wrapped my head around positioning, so I don't position it for now.
UIView* haloView = [UIView new];
haloView.backgroundColor = [UIColor clearColor];
NSLayoutConstraint* constraintHeight = [NSLayoutConstraint constraintWithItem:haloView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:flagButton attribute:NSLayoutAttributeHeight multiplier:2.0 constant:0.f];
NSLayoutConstraint* constraintWidth = [NSLayoutConstraint constraintWithItem:haloView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:flagButton attribute:NSLayoutAttributeWidth multiplier:2.0 constant:0.f];
NSLayoutConstraint* constraintCenterX = [NSLayoutConstraint constraintWithItem:haloView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:flagButton attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.f];
NSLayoutConstraint* constraintCenterY = [NSLayoutConstraint constraintWithItem:haloView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:flagButton attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.f];
[self.view insertSubview:haloView belowSubview:flagButton];
haloView.translatesAutoresizingMaskIntoConstraints = NO;
constraintCenterX.active = YES;
constraintCenterY.active = YES;
constraintHeight.active = YES;
constraintWidth.active = YES;
PulsingHaloLayer *halo = [PulsingHaloLayer layer];
[haloView.layer insertSublayer:halo atIndex:0];
halo.radius = 50.0;
halo.haloLayerNumber = 4;
halo.duration = 4.0;
This should normally provide me with the pulsing animation shown in the linked library. And I do get it, somewhat. The behavior is hard to describe, but it appears to start correctly, then abruptly stop when it should loop, then restart again a second later. Basically, it does not seem to loop properly as it should, and I have no idea why.
This is the view hierarchy. The last "UIView" is the one with the Halo layer.

These are the UIView's properties as shown by the debugger.

These are the UIScrollView's properties.

Thank you for your help.