Once swiping on UIImageView with animation the animation stops - ios

I have a UIImageView with animationImages and it works fine
self.imageView.animationImages = [self loadImages];
self.imageView.animationDuration = 15;
[self.imageView startAnimating];
I've added a swipe gesture that, in the selector of the swipe I want to do the following:
find the image that is currently shown
move to the next/previous image
continue the animation

Post your gesture recognizer action method.
It will take some tinkering, but it should be possible to do what you want to do.
I suspect that you will have to stop the animation, juggle the order of the images in the animation array, and then start the animation again. The image view should revert to the normal content image when the animation stops, so you might want to set the normal image to the image on which you stop if you get flickering when you stop the animation and restart it.

Related

A UIImageView animation was stopped by something

I create a UIImageView with animationImages.
Like this :
The Code
The imageView execute perfectly most time怂But when I show a custom view which poped up using facebook's pop animation in common rootView,the imageView animation would be stopped. I do not konw is this wrong has something about pop.Does anybody can give me some suggestion?
First , the animation of images may ends while the popup is presented so setting animationRepeatCount to zero makes it loop again when it reaches final image
imageView.animationRepeatCount = 0;
Second you may start the animation again in viewDidAppear method
-(void) viewDidAppear
{
[self.imageView startAnimating];
}
Finally it's better to declare the imageView
var imageView:UIImageview!
out of viewDidLoad

UISwipeGestureRecognizer interferes with slider

I have a view in an iOS application (Obj-C) which has an image view in the centre, and immediately below that a slider.
The image view shows album artwork, and the slider can be used to adjust the now-playing track position.
There is also a pair of left and right Swipe Gesture Recognizers. These are used to skip to the next or previous tracks.
The problem is that the swipe gesture recognizers seem to over-ride the users moving the slider thumb.
In my gesture recognizer code I check that the point touched was inside the image view, but it still stops the slider from being moved. (The thumb moves, but jumps back to it's original position when you remove your finger).
This is the code I use to reject the gesture if it's not inside the image view.
- (IBAction)swipeLeftGestureAction:(UISwipeGestureRecognizer *)sender {
// Get the location of the gesture.
CGPoint tapPoint = [sender locationInView:_artworkImageView];
// Make sure tap was INSIDE the artwork image frame.
if( (tapPoint.x <0)
|| (tapPoint.y < 0 )
|| (tapPoint.x > _artworkImageView.frame.size.width)
|| (tapPoint.y>_artworkImageView.frame.size.height))
{
NSLog(#"Outside!");
return;
}
NSLog(#"Swipe LEFT");
[_mediaController skipNext];
}
So my question is, how do I limit the gesture to work ONLY when swiped across the image view?
Try to put the code that restricts the gesture's area in gestureRecognizer:shouldReceiveTouch: and return NO in case you don't want the gesture to receive this touch. It should prevent the gesture from over taking the slider interaction.
If you're only interested in swipes that are inside the image view, then you should add the swipe gesture recognizer to the image view instead of adding it to your entire view. Then you won't need any special logic.
There is a dedicated method for checking if a point is inside a view
BOOL isPointInsideView = [_artworkImageViewpointInside:tapPoint withEvent:nil];
But I think what is happening is that if you will look at the tapPoint is that it actually outside of your imageView
And if your slider is really close to the imageView so the slider captures the movement, what you should do is check on the slider if it is intended for the slider and propagate on to the imageView if needed
Or inherit the UISlider and reduce its response rect

Button not preforming action from being tapped while animating in Xcode using UIView Animation

I have a game that I am making and I am trying to move a button named tapMe using UIView Animation but I need it to be tapeable while it is being animated.
[UIView animateWithDuration:0.5 animations:^{
_tapMe.center = CGPointMake(xRandom, yRandom);
}];
Where xRandom and yRandom are randomly generated integers and _tapMe is connected to the button, I am certain because it does move.
When you use animateWithDuration, the button's frame is moved to its final position immediately (it will be touchable there), but the presentation layer is animated, so where you see the button during the animation is not where the touchable area will be. You either need to hit test the presentation layer, or animate the button by moving it in small increments with a timer. See the answer here for more detail, UIButton can't be touched while animated with UIView animateWithDuration

How would i go about making 4 UIImages on UIView Blink or remove based on Timing?

I dont have or know the code yet to be able to create this project but basically it would work like a Gauge meter where i have a UIView with a Background and a Test tube image where inside the Test tube image, would have 4 rectangular images stacked on top of eachother
Each having their own properties. The very bottom, the on on top and the middle and the last one on the very top.
My question is, how would i be able to remove the top one based on a NSTimer and so forth till the last Bar image is left ?
I was thinking of using an NSMutableArray to hold the images this way:
NSMutableArray *testTube = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:#"bar1"], // 0
[UIImage imageNamed:#"bar2"], // 1
[UIImage imageNamed:#"bar3"], // 2
[UIImage imageNamed:#"bar4"],nil];
But aftter this in the IBAction method, i did a:
[testTube removeObjectAtIndex: 3];
and it didnt remove it on the app when i clicked the IBAction Button to test it out if i can successfully manipulate the bar4.png
Where am i going wrong ? and as for the timer, it is suppose to remove them one by one in 5 minutes till there is no bar left.
What displays an image on the screen is a UIImageView (not a UIImage, as your question seems to imply). If you have one of those that you want to remove from the screen, you can do one of the following:
[imageView removeFromSuperview];
or
imageView.hidden = YES;
Here's how I would suggest to handle it:
Set up 4 image views in Interface Builder. Drag the images into your project and set up the image views to line up in your test tube. There is an image property on image views. Enter the name of each image and the image will show up. Make the image view the same size as the image it contains so it doesn't get scaled or stretched.
Then create an IBOutlets for each of your images views by control-dragging from the image view into your view controller's header. Name the top image view imageView1, the next one imageView2, the next imageView3, and the bottom one imageView4.
Define an NSArray property imageViews in your view controller's header. In your viewDidLoad method, add this line:
self.imageViews = #[imageView1, imageView2, imageView3, imageView4];
Also add a counter instance variable. Let's call it imageIndex;
When your view controller first displays, all 4 image views will be visible.
Finally, you need to start a repeating NSTimer that:
sets the hidden property on the image view at the current index to YES.
The timer method would look something like this:
- (void) hideAnImageView: (NSTimer *) theTimer;
{
self.imageViews[imageIndex].hidden = YES;
imageIndex++;
if (imageIndex + 1 > [self.imageViews count]
[theTimer invalidate];
}

Rotation makes UIImageView moves up -iOS

I am using the following code to rotate my image view and it is working fine..but whenever I change the view and go back. my image view moves up and eventually goes off the screen.. Any ideas why? Thanks..
self.anchorImage.layer.anchorPoint = CGPointMake(1.0,0.0);
CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(1);
[self.imageView setTransform:cgaRotateHr];

Resources