I hit the play button 6 image views will be filled with the pressed images, I want it to view 1, wait 1 second,view2, wait one second etc.
which code should I be adding to:
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];
I tried this: but it doesn't work:
[self performSelector:#selector(GameViewController) withObject:nil afterDelay:1];
hope someone knows bye thanks
EDIT explaining my code more
-(IBAction)play {
[self performSelector:#selector(delay) withObject:nil afterDelay:5.0];
play.enabled=NO;
UIImage *img = [UIImage imageNamed:#""];
if (imageview7.image == nil) {
if([textview.text isEqualToString:labelsText.text]){
-(void)delay {
[imageview7 setImage:imageview1HG.image];
[imageview8 setImage:imageview2HG.image];
[imageview9 setImage:imageview3HG.image];
[imageview10 setImage:imageview4HG.image];
[imageview11 setImage:imageview5HG.image];
[imageview12 setImage:imageview6HG.image];}
}
else {
-(void)delay {
[imageview7 setImage:imageview1H.image];
[imageview8 setImage:imageview2H.image];
[imageview9 setImage:imageview3H.image];
[imageview10 setImage:imageview4H.image];
[imageview11 setImage:imageview5H.image];
[imageview12 setImage:imageview6H.image];}
I guess you want to setImage on UIImageView one after the other after a delay.Here is the code for it.
Definition
#interface ViewController : UIViewController
{
NSMutableArray * imageViews;
NSMutableArray * images;
int count;
NSTimer * timer1;
}
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image;
-(void)update;
-(IBAction)setImageOnViewOneAfterOther;
#end
Definition
-(void)setImageForView:(UIImageView *)imageView withImage:(UIImage *)image{
[imageView setImage:image];
}
-(void)update{
if (count < [imageViews count]) {
[self setImageForView:[imageViews objectAtIndex:count] withImage:[images objectAtIndex:count]];
count ++;
}else{
[timer1 invalidate];
}
}
-(IBAction)setImageOnViewOneAfterOther{
count = 0;
imageViews = [[NSMutableArray alloc] initWithObjects:img1v,img2v,img3v,img4v,img5v,img6v, nil]; // Set of all UIImageViews
images = [[NSMutableArray alloc] initWithObjects:img1,img2,img3,img4,img5,img6, nil];//Set of all UIImage's where img = [UIImage imageNamed:#"someImage1.png"];
timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(update) userInfo:nil repeats:YES];
}
Why not animate it?
UIImageView* animatedImageView = [[UIImageView alloc]init];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.gif"],
[UIImage imageNamed:#"2.gif"],
[UIImage imageNamed:#"3.gif"],
[UIImage imageNamed:#"4.gif"], nil]; //etc
animatedImageView.animationDuration = float([animatedImageView.animationImages count]);
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];
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;
}
how are you guy's?
I want to make a new instance variable every time a timer is called for e.g.
numberofObjects += 1;
i = numberofObjects;
UIImageView *Object[i] = [[UIImageView alloc] initWithFrame:CGRectMake(randomx,0,36 ,36)];
UIImage *imag = [UIImage imageNamed:#"ball.png"];
[Object[i] setImage:imag];
[self.view addSubview:Object[i]];
Is there a way to do this?
Any comments will be appreciated.
This isn't too hard to do. I make the assumption that you are only going to have a maximum number of UIImageViews, as this can add a lot of overhead, and you may run into problems if it's allowed to continue forever. In the .h file,
#interface viewController : UIViewController {
int numberAdded;
NSTimer * timer;
UIImageView * currentImageView;
NSMutableArray * arrayOfImageViews;
}
- (void)addNewImageView;
#end
In the .m file:
#define MaxImageViews 20 // This is changeable!
#implementation viewController
- (void)viewDidLoad; {
[super viewDidLoad];
numberAdded = 0;
arrayOfImageViews = [[NSMutableArray alloc] init];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(addNewImageView) userInfo:nil repeats:YES];
}
- (void)addNewImageView; {
if(numberAdded >= MaxImageViews){
[timer invalidate];
timer = nil;
return;
}
int randomX = arc4random() % 320; // Gives value from 0 - 319.
int randomY = arc4random() % 480; // Gives value from 0 - 479.
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(randomX, randomY, 36, 36)];
imageView.image = [UIImage imageNamed:#"ball.png"];
[self.view addSubview:imageView];
[arrayOfImageViews addObject:imageView];
[currentImageView release];
currentImageView = imageView;
}
- (void)dealloc; {
[currentImageView release];
[arrayOfImageViews release];
[super dealloc];
}
#end
This should keep track of all of the imageViews in the array arrayOfImageViews, and you can access the i-th imageView by calling [arrayOfImageViews objectAtIndex:i]. The currentImageView pointer keeps track of the latest UIImageView added. Hope that helps!
Store the image views' pointers in an NSMutableArray object.
I want to change the image of the buttons of UIActionSheet, I have images for each button, and I want each button show the image I want. I searched the web I found a lot of answers but they didn't work.
Here is the initialization of the UIActionSheet
-(IBAction)showActionSheet:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"title" delegate:self cancelButtonTitle:#"Cancel Button" destructiveButtonTitle:nil otherButtonTitles:#"Other Button 1", #"Other Button 2", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleDefault;
[popupQuery showInView:self.view];
[popupQuery release];
}
I create a subclass CustomActionSheet derived UIActionSheet, and implement a method called customizeGUI.
I use CustomActionSheet like UIActionSheet, except I must call method customizeGUI of subclass in willPresentActionSheet delegate:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
if ([actionSheet isKindOfClass:[CustomActionSheet class]]) {
CustomActionSheet *sheet = (CustomActionSheet*)actionSheet;
[sheet customizeGUI];
}
}
(CustomActionSheet.m)
- (void)customizeGUI {
UIImageView *imgvwBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg_actionsheet.png"]];
CGRect rect = self.bounds;
imgvwBackground.frame = rect;
[self insertSubview:imgvwBackground atIndex:0];
[imgvwBackground release];
int buttonIndex = 0;
UIImage *imgButtonDestructive = [UIImage imageNamed:#"btn_actionsheet_destructive.png"];
UIImage *imgButtonCancel = [UIImage imageNamed:#"btn_actionsheet_cancel.png"];
UIImage *imgButtonNormal = [UIImage imageNamed:#"btn_actionsheet_normal.png"];
for (UIView *sub in self.subviews) {
NSString *className = [NSString stringWithFormat:#"%#", [sub class]];
if ( ([className isEqualToString:#"UIThreePartButton"]) //iOS 4
|| ([className isEqualToString:#"UIAlertButton"]) ) { //iOS 5
rect = sub.frame;
sub.hidden = YES;
UIButton *btn = [[UIButton alloc] initWithFrame:rect];
UIImage *imgForButton = nil;
if (buttonIndex == self.cancelButtonIndex) {
imgForButton = imgButtonCancel;
}
else if (buttonIndex == self.destructiveButtonIndex) {
imgForButton = imgButtonDestructive;
}
else {
imgForButton = imgButtonNormal;
}
NSString *sTitle = [self buttonTitleAtIndex:buttonIndex];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:19];
[btn setBackgroundImage:imgForButton forState:UIControlStateNormal];
[btn setTitle:sTitle forState:UIControlStateNormal];
btn.tag = buttonIndex;
[btn addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
[btn release];
buttonIndex++;
}
}
}
- (void)buttonClicked:(id)sender {
UIButton *btn = sender;
if ([self.delegate respondsToSelector:#selector(actionSheet:clickedButtonAtIndex:)]) {
[self.delegate actionSheet:self clickedButtonAtIndex:btn.tag];
}
[self dismissWithClickedButtonIndex:btn.tag animated:YES];
}
Hope this way can help you and give you an idea to customize UIActionSheet
If you change these sizes, not only might you make your application less usable, but that may violate Apple's Human Interface Guidelines, leading to a rejection of your application when submitted.
Here is the example how to use UiActionsheet by Apple
Looks like you'll just have to create your own class. I'd look into subclassing either UIView or UIActionSheet. There are those PSD things around that you can get the images you'll need, pending copyright.
EDIT: If you do end up creating your own class, and its any good, consider uploading it to http://cocoacontrols.com/
here is my code :
-(void) createNewImage {
UIImage * image = [UIImage imageNamed:#"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView setCenter:[self randomPointSquare]];
[imageViewArray addObject:imageView];
[[self view] addSubview:imageView];
[imageView release];
}
-(void)moveTheImage{
for(int i=0; i< [imageViewArray count];i++){
UIImageView *imageView = [imageViewArray objectAtIndex:i];
imageView.center = CGPointMake(imageView.center.x + X, imageView.center.y + Y);
}
}
-(void)viewDidLoad {
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:#selector(onTimer) userInfo:nil repeats:YES];
displayLink = [CADisplayLink displayLinkWithTarget:self selector:#selector(onTimer2)];
[displayLink setFrameInterval:1];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
imageViewArray = [[NSMutableArray alloc]init];
}
So what I want to do is http://www.youtube.com/watch?v=rD3MTTPaK98.
But my problem is that after imageView is created(createNewImage) it stops after 4 seconds (maybe due to the timer).I want that imageView continue moving while new imageView are created. How can I do this please ? sorry for my english I'm french :/
Instead, keep a reference to the point you want all your images to move too. Using an NSTimer and moving all the images yourself in the timer will eventually slow down your app a lot (I know from experience). Use UIView animation blocks, and just tell it to move to the point when you create it.
-(void) createNewImage {
UIImage * image = [UIImage imageNamed:#"abouffer_03.png"];
imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
[imageView setCenter:[self randomPointSquare]];
//Move to the centerPoint
[self moveTheImage:imageView];
[imageViewArray addObject:imageView];
[[self view] addSubview:imageView];
}
-(void)moveTheImage:(UIImageView *)imageView {
[UIView animateWithDuration:1.0
animations:^{
[imageView setCenter:centerPoint];
}];
}
-(void)viewDidLoad {
[super viewDidLoad];
imageViewArray = [[NSMutableArray alloc]init];
//IDK what all that other code was
centerPoint = self.view.center;
}
EDIT: Finding the UIImage during animation
You need to reference the presentation layer of the UIImageView to find its position during an animation
UIImageView *image = [imageViewArray objectAtIndex:0];
CGRect currentFrame = [[[image layer] presentationLayer] frame];
for(UIImageView *otherImage in imageViewArray) {
CGRect objectFrame = [[[otherImage layer] presentationLayer] frame];
if(CGRectIntersectsRect(currentFrame, objectFrame)) {
NSLog(#"OMG, image: %# intersects object: %#", image, otherImage);
}
}