Animated Background - ios

I am making an app in which there are two buttons in the center. The background is there and I need the background to have an animation. With that said I mean like little raindrops constantly falling in the background. I have no clue on how to do this. My customer really, really wants this. Thanks!

Make sure the images are named in numerical order with the number at the end of the name. Then drag and drop the file of images into your Xcode folder area. Then you reference only the image name and not the number in animatedImageNamed.
You need to create an ImageView the size of the Background for each device you plan on using.
//place this in your viewDidLoad
UIImageView * background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 55)];
UIImage * image = [UIImage animatedImageNamed:#"MovingCar" duration:3.6];
background.image = image;
[self.view setBackgroundView: background];
You can change the duration to suit your needs accordingly.

You could use the UIView method animateWithDuration:animations: or one of it's variants that has a completion method to animate images from the top to the bottom of the screen. Take a look at the Xcode docs on that method, and search the web for examples.
As the other poster says, this site is for helping people with problems, not for asking others to provide you with ready-made solutions.
I could bang out some animation code for you that would create an endless stream of falling raindrops, but it would probably take me a couple of hours to get it fully working, and I'd have to charge you for it. (Plus I'm not very familiar with Swift so I'd have to do some translation from Objective-C, which is my day-to-day programming language.)

Related

iOS: Working with custom ui elements

I'd like to use some custom UI elements for an app I'm writing. They're all encased in a .psd in separate layers. Once I isolate them, what's the best way to use them in my app? I've been looking for a tutorial but I can't find anything.
I.e. for a UIToolbar, do I add it as a subview?
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(titleToolbar.frame.origin.x,
titleToolbar.frame.origin.y, titleToolbar.frame.size.width,
titleToolbar.frame.size.height)];
imgView.image = [UIImage imageNamed:#"toolbar1"];
[titleToolbar addSubview:imgView];
For a UIButton, do I just add it as the background image? Should I be subclassing things?
Forgive my ignorance :(
The best thing what you should do, is subclassing, and make universal components. Then like you did, add from code, and add as subviews.

iOS AwesomeMenu Delegation and Overlays

I'm adding this menu to an app I'm working on: http://mobiledevelopertips.com/open-source/ios-open-source-animated-menu.html
I'm relatively green to Objective C (only been working on it for less than a month) and I'm not entirely sure how to do the following:
1) I want to add a gray overlay to the entire screen when I hit the button to open the menu. I've looked for solutions but a lot of people seem to recommend DSActivityView which doesn't work for me... I don't need that loading bubble. I guess I could download the source and remove the bubble, but that might require more effort than it's worth.
I would think that I could just instantiate an imageView, drop it at 0,0 and expand it to the bounds of the screen, sourced with a transparent gray PNG file...like
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"transparent_gray.png"]];
imageView.frame= CGRectMake (0,0,screenWidth,screenHeight);
[viewController addSubview:imageView];
However, this approach probably won't work ( I'm guessing it won't cover the nav controllers like tab bar and status bar). Furthermore, I'm not really sure how I'd get to access the viewController from within AwesomeMenu. I assume I'd have to pass a reference of the viewController that is instantiating the AwesomeMenu into one of AwesomeMenu's functions in order to be able to deploy an imageView into the viewController?
2) I want to write a delegate that will fire when the opening menu animations stop, so I can write text onto the overlay'd screen. Is there a super easy way to do this or am I going to have to just guestimate with some timer start/callback and make the callback write the text onto my screen? Oh - I've never written a delegate before but I assume it becomes slightly complicated when I want them to fire upon animation end.
Um, I think you have some preconceived notions about the way UIKit works. For 1), I suggest searching SO for "view covers screen" and get a better understanding of the issue, especially associated with view animation. Secondly, there are many ways to accomplish your 2) item. If you have the source to AwesomeMenu you can just modify whatever animations it performs. If the animation was done with animateWithDuration:animations: you can just add a completion: block. If you have a need to do your completion animation from several places, you might consider a delegate. You might be able to write a category for AwesomeMenu to add the functionality. In your case, I think a simple code modification is all you need. Hard to tell without more code/facts, though.

ios custom progress bar designing

I want to create a custom progress bar for my app. I am new to iOS development and finding it difficult to understand codes on google which confuse me a lot. What I want is like growing animated progress bar.
e.g: like showing progress in terms of a tree growth from small plant(to a complete tree) which denotes the process completion.
Where and how to start? And also is Core Graphics or cocos2d which one will be apt for this?
If you're doing something graphical like a tree growing, do you already have the animation you want to use as a series of images?
If so, you could use a UIImageView. Whenever you want to update your progress bar, just check the progress of your task, and use that to work out which number image to display. So if you had twelve images, you could find the percentage complete of your task, divide by 100 then multiply by twelve (and then convert to an int) to get the image number you want.
Once you've done that, just get the appropriately named image and put it in your image view:
self.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"frame-%i", myImageNumber]];
As for when to do the progress check, that depends on the task you are doing. Some tasks have a natural place to inject a callback to update the UI, and for others it's better to just use a timer.
you cannot change much in uiprogressbar instead you can use UISlide to behave like progressbar
.
you can only change the frame of progressbar as:-
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle
:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(0,0,320,10)];
you can create a uiSlider and make its ThumbImage to nil,setMinimumTrackImage ans maxtrackImage and then use the custom function on it to show the progress
custom UISlider
https://github.com/jdg/MBProgressHUD
Try this code its modst widely used open source code for your kind of purpose

how to add the dimmed background found in UIAlertView

Im making a custom dialog thats similar to UIAlertView, and was wondering if anyone had any ideas how I can emulate the dimming background as in the photo below.
I agree that you should be very careful to have a real justification for redoing something that is already there, but if you really need it, it's easy:
Create a PNG image with the same size as the targeted device's screen, with alpha. TFill the image black, and add a radial opacity gradient, so that in the center, it is relatively transparent, while towards the screen edges it'll be more opqaue. This effect is called vignetting. Maybe there even is a vignetting filter on your preferred image editor, which you could use on a completely transparent image.
This image approach also has the benefit of allowing you to use completely different effects of fading away the background.
Create a UIImageView with the vignette image, and transparent background. Add the view to your app's Window, on top of all other views, but below your alertView:
UIImageView *vignetteView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"vignette.png"]];
vignetteView.backgroundColor = [UIColor clearColor];
vignetteView.userInteractionEnabled = YES; //this means users won't be able to touch the UI elements below
[self.view.window insertSubview: vignetteView belowSubview: myAlertView];
First off, I'd recommend that you do your best to avoid the need for a custom modal dialog. You can usually give your feedback contextually within the flow of your application's actual views.
If your app targets iOS 5 only, UIAlertView offers three new styles to allow text input, secure text input, or a user name and password combo.
If you still need a custom modal alert, and you're looking to stay consistent with the iOS look and feel, and maintain resolution independence, I'd recommend that you avoid using static graphical assets. Instead, take the (somewhat hackish) approach of subclassing UIAlertView, and adding your own controls to it. You can find examples of doing this here and here.

Adding Objects to View

Im making a game of sorts, where balls are added to the screen. I need to be able to add custom balls (different speeds/images, ect) at time intervals (i.e. ball type 1 gets added every 15 seconds, whereas ball type 2 gets added every 30 seconds). I need these balls to be UIImageView (at least with the setup I have right now to check collisions).
Any ideas on how I can do this?
Also, How to make the player (a UIImageView) the start button. I have an IBAction that starts the game. I cannot connect the UIImageView and the IBAction though...
Only a partial answer first, but really you don't want to use UIImageView for user interaction. A UIButton can be set to the type 'custom' and then display an image (you can set the image in interface builder or programmatically):
btnImage = [UIImage imageNamed:#"image.png"];
[btnMyButton setImage:btnImage forState:UIControlStateNormal];
It is then much easier to pick up IBAction etc.
As regards creating the balls dynamically, creating a new UIImageView programmatically is easy using the initWithImage method, I suggest you read up on the UIImageView class reference at http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html.
UIImageView inherits from UIView so after creating each image, just add it as a sub view using something like:
[self.view addSubView:newImageView];
Regarding the timer element, NSTimer is the place to look for this. I don't have much experience using these but it should be straightforward. Reference can be found at:
http://developer.apple.com/library/mac/ipad/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
Hth

Resources