I am trying to implement an animation set of images on my application.
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"myImage1.png"],
[UIImage imageNamed:#"myImage2.png"],
[UIImage imageNamed:#"myImage3.png"],
[UIImage imageNamed:#"myImage4.gif"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];
Ok, but the problem is that i am using an API function to place a marker on a map.
That function is the following:
RMMarker *newMarker;
UIImage *blueMarkerImage = [UIImage imageNamed:#"marker.png"];
newMarker = [[RMMarker alloc] initWithUIImage:blueMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
[mapView.contents.markerManager addMarker:newMarker AtLatLong:position];
[newMarker release];
The problem is that "initWithUIImage:" only works with UIImage, not with UIImageView.
So, how can i solve it??
UPDATE: My new code that is not working:
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"marker0.png"],
[UIImage imageNamed:#"marker1.png"],
[UIImage imageNamed:#"marker2.png"],
[UIImage imageNamed:#"marker3.png"],
[UIImage imageNamed:#"marker4.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 10; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:[myAnimatedView image] anchorPoint:CGPointMake(0.5, 1.0)];
[mapView.contents.markerManager addMarker:newMarker AtLatLong:markerPosition];
You can try using image message from UIImageView:
newMarker =
[
[RMMarker alloc]
initWithUIImage:[myAnimatedView image]
anchorPoint:CGPointMake(0.5, 1.0)
];
Or, if what you need is creating a UIImageView then you can try:
UIImageView *newMakerImageView =
[[UIImageView alloc] initWithImage:
[
[RMMarker alloc]
initWithUIImage:yourImageHere
anchorPoint:CGPointMake(0.5, 1.0)
]
];
UIImageView *myAnimatedView = [UIImageView alloc]
That may just be a copy/paste error, but you forget the init.
UIImageView *myAnimatedView = [[[UIImageView alloc] initWithFrame:[self bounds]] autorelease]
Related
I want to aniate array of imageview and textview together in uiview.
Right now i am animating image view separate and textview separate which is not looking that good.
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
baseView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:252.0/255.0 blue:199.0/255.0 alpha:1.0];
[self.view addSubview:baseView];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 30, 200, 200)];
self.imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
nil];
// all frames will execute in 25 seconds
self.imageView.animationDuration = 20;
[self.imageView startAnimating];
[baseView addSubview:self.imageView];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 250, 300, 200)];
self.textView.textColor = [UIColor brownColor];
myArray = [[NSMutableArray alloc] initWithObjects:#"string1", #"string2", #"string3", #"string4", #"string5", ...., nil];
[NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:#selector(updateText:)
userInfo:nil
repeats:YES];
[baseView addSubview: self.textView];
- (void)updateText:(NSTimer *)theTimer
{
if (index < [myArray count])
{
self.textView.text = [self.myArray objectAtIndex:index];
index++;
}
else
index = 0;
[timer invalidate];
}
How i can animate both image view and textview together within UIView.
Thanks for help.
How about this,,
in your .h
NSArray *imgsArray;
NSArray *myArray;
int indx;
NSTimer *timer;
and start your animation
-(void)start{
imgsArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"1.png"],[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],nil];
myArray = [[NSMutableArray alloc] initWithObjects:#"string1", #"string2", #"string3", #"string4", #"string5", nil];
timer = [NSTimer scheduledTimerWithTimeInterval:2.5
target:self
selector:#selector(updateText:)
userInfo:nil
repeats:YES];
}
- (void)updateText:(NSTimer *)theTimer
{
if (indx < myArray.count)
{
self.textView.text = [self.myArray objectAtIndex:indx];
self.imageView.image = [self.imgsArray objectAtIndex:indx];
indx++;
}
else
indx = 0;
}
How can implement image sliding down animation in ios app?
I've used this code:
imageview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],[UIImage imageNamed:#"img12.png"],[UIImage imageNamed:#"img13.png"],nil];
imageview.animationDuration = 10.00;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
But this is only a simple slide show.
Help me.
try with this code..
imageview = [[UIImageView alloc] initWithFrame:self.view.frame];
imageview.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],[UIImage imageNamed:#"img12.png"],[UIImage imageNamed:#"img13.png"],nil];
imageview.animationDuration = 1.25;
imageview.animationRepeatCount = 10;
[imageview startAnimating];
[self.view addSubview:animationView];
[imageview release];
Please try following code
-(void) createNewImage {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"img10.png"],
[UIImage imageNamed:#"img11.png"],
[UIImage imageNamed:#"img12.png"],
[UIImage imageNamed:#"img13.png"],nil];
[imageView setAnimationRepeatCount:10];
imageView.animationDuration =1.5;
[imageView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:#selector(setLastImage:) userInfo:nil repeats:NO];
}
-(void)setLastImage:(id)obj
{
[imageView performSelectorOnMainThread:#selector(setImage:) withObject:[UIImage imageNamed:#"img12.png"] waitUntilDone:YES];
}
You can change the centre of UIImageView using imgVw.centre, you can update the centre with NSTimer. Vary the centre according to the screen, you can get screen height from
[[UIScreen mainScreen]bounds].size.height
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:#selector(updateTimer:)
userInfo:nil
repeats:YES];
- (void)updateTimer:(NSTimer *)theTimer {
//update centre;
imgVw.centre.y += 4;
// you can update the image also if needed use if case
imgVw.image = image2;
}
I have added a UIView, On that UIImageView using UIBuider,
Now I want to apply animation on that imageView, so I'v taken an array of images & adding that
array to imageView through this code
NSArray *animationArray=[[NSArray alloc]init];
animationArray=[NSArray arrayWithObjects:
[UIImage imageNamed:#"rabbit1.png"],
[UIImage imageNamed:#"rabbit2.png"],
[UIImage imageNamed:#"rabbit3.png"],
[UIImage imageNamed:#"rabbit4.png"],
[UIImage imageNamed:#"rabbit5.png"],
[UIImage imageNamed:#"rabbit6.png"],
[UIImage imageNamed:#"rabbit7.png"],
[UIImage imageNamed:#"rabbit8.png"],
[UIImage imageNamed:#"rabbit9.png"],
[UIImage imageNamed:#"rabbit10.png"],
[UIImage imageNamed:#"rabbit11.png"],
[UIImage imageNamed:#"rabbit12.png"],
[UIImage imageNamed:#"rabbit13.png"], nil];
tempImageView.animationImages=animationArray;
tempImageView.animationDuration=2;
tempImageView.animationRepeatCount=0;
[tempImageView startAnimating];
tempImageView is created using UIBuider
But it is not woking, isn't showing anything.
There seems to a bug in the story board auto layout..i found the same no result..
Try it via code this works..
mainImageView = [[UIImageView alloc]init];
NSArray *animationArray = [[NSArray alloc]init];
animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"], nil]; //add your images here
[mainImageView setFrame:CGRectMake(50,50,100,100)];
mainImageView.animationImages = animationArray; //mainImageView is imageview
mainImageView.animationDuration = 2;
mainImageView.animationRepeatCount = 0;
[mainImageView startAnimating];
[self.view addSubview:mainImageView];
I have an odd question here. I have two animations set up for a simple page flip. I then have a button that randomly generates a 1 or a 0. If the number is 0 then it performs one animation, if its 1 it performs another.
The issues I'm seeing is that this all runs fine on the simulator, but on the device it doesn't perform the animation if the random number is 0.
Any clues?
-(IBAction)pageTurn:(id)sender {
int randomNumber = arc4random() %2;
NSLog(#"randomNumber = %d", randomNumber);
if (randomNumber == 0) {
[self turnPageForward];
} else {
[self turnPageBackward];
}
}
-(void)turnPageForward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"PageTurnOne.png"],
[UIImage imageNamed:#"PageTurnTwo.png"],
[UIImage imageNamed:#"PageTurnThree.png"],
[UIImage imageNamed:#"PageTurnFour.png"],
[UIImage imageNamed:#"PageTurnFive.png"],
[UIImage imageNamed:#"PageTurnSix.png"],
[UIImage imageNamed:#"PageTurnSeven.png"],
[UIImage imageNamed:#"PageTurnEight.png"],
[UIImage imageNamed:#"PageTurnNine.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
-(void)turnPageBackward {
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"PageTurnNine.png"],
[UIImage imageNamed:#"PageTurnEight.png"],
[UIImage imageNamed:#"PageTurnSeven.png"],
[UIImage imageNamed:#"PageTurnSix.png"],
[UIImage imageNamed:#"PageTurnFive.png"],
[UIImage imageNamed:#"PageTurnFour.png"],
[UIImage imageNamed:#"PageTurnThree.png"],
[UIImage imageNamed:#"PageTurnTwo.png"],
[UIImage imageNamed:#"PageTurnOne.png"],
nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 480)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = .5; // seconds
myAnimatedView.animationRepeatCount = 1; // 0 = loops forever
[myAnimatedView startAnimating];
[self.view addSubview:myAnimatedView];
[myAnimatedView release];
}
Usually, when code fails on the device but not the simulator (or vice versa) the culprit is a library or other compiled source that was compiled for one hardware but not the other.
Another related possibility is that a resource was not added properly so that it is not included in the final build for the device. I would check the image files in the method that does not work.
You should also confirm if the turnPageForward is being called at all. That will give you a clue as to where the problem lays.
This is the strangest error i have come across.
Am trying to add a countdown animation onto a Class that extends UIView. The code is shown below:
NSArray *myImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:#"3.png"], [UIImage imageNamed:#"2.png"], [UIImage imageNamed:#"1.png"], [UIImage imageNamed:#"Go.png"], nil];
UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 80, 80)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 3;
myAnimatedView.animationRepeatCount = 0;
[self addSubview:myAnimatedView];
[myAnimatedView startAnimating];
It is just not appearing on the screen. Any Ideas?
Have you made sure those images are added to your project?
Can you add them as a flat image (non-animated) -- as in:
UIImageView *myAnimatedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"3.png"]];
[self addSubview:myAnimatedView];
(just to make sure that works first)?
If, instead of extending UIView, you extended UIImageView, would that make a difference?
Try switching the last 2 lines. From:
[self addSubview:myAnimatedView];
[myAnimatedView startAnimating];
To:
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];