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.
Related
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.)
I'm fairly new to modern programming (the last serious experience I had was AMOS on my old Amiga!), but I've done my best to learn objective C with a view to developing an app (for iOS only at the moment). I've got a (hopefully very simple) question which I've done my best to research already without any joy.
I've got the bulk of my relatively basic app laid down already. From my home ViewController, I've got four options, all of which have colour-coded buttons, linked by segue to the content ViewControllers.
As a nice flourish, more than anything else, I'd like to make the whole screen flash briefly in the colour of the button pressed (this app is aimed at non-programmers, and a bit of theming will not only make things look good, but also hopefully aid orientation/ intuititivity.
So far I have tried:
adding a new ViewController with a screen blank except for the themed colour and an automated custom segue controlled by NSTimer. // This is sub-optimal as if the user wants to navigate back to the home page they have to jump through two pages rather than one, and if they're a bit slow then they may get stuck in a loop.
dicking around with NSTimer and self.window.backgroundColor/ setBackgroundColor. // both of these options end up with my app crashing - probably due to coding ineptitude!
Any ideas? For example, if my user clicked the 'Emergency Guidelines' UIButton, then I would have the screen flash red (the chosen theme colour for this section) for a barely perceptibly but subconsciously awesome period before seamlessly transitioning the app to the relevant page.
Sorry if it's a bit of a noobish question. I'm keen to hear any answers, even appropriately directed tough love.
I would suggest a different way. Don't use an extra viewController, instead add a colored UIView that covers the whole screen when the button was pressed. Animate a fade out, and once it's faded out completely remove that view and perform the push to the next viewController.
That's probably the easiest way, takes only this much code:
- (IBAction)demoButtonPressed:(UIButton *)sender {
UIView *flashView = [[UIView alloc] initWithFrame:self.view.bounds];
flashView.backgroundColor = [UIColor redColor];
[self.view addSubview:flashView];
[UIView animateWithDuration:0.3 delay:0.1 options:0 animations:^{
flashView.alpha = 0.0f;
} completion:^(BOOL finished) {
[flashView removeFromSuperview];
[self performSegueWithIdentifier:#"pushDemo1" sender:sender];
}];
}
Play around with duration and delay until you are satisfied.
have you looked into core animation? it would help if you therw up some code but i thing Apple's Core Animation tutorial is pretty straight forward with how you can trigger animation effects especially if a button is pressed like you mentioned for your color flash idea.
https://developer.apple.com/library/Mac/DOCUMENTATION/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
you can also pull this up in X code which i suggest, or youtube some tutorials or github etc.
veritas
I'm taking screen captures like this:
UIView *snapshot = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
Is there any way I could place something on the screen (like by adding a UIView), take a snapshot as above that includes this item, and then remove this item, in such a way that the user never actually sees the briefly-added item?
The best way to do this is to take the screenshot and then copy that something in after you do the screenshot.
Hopefully that something is something that has static content, and that way you won't have to make something's UIView visible. You can use a technique like one that is described in this related question.
I have a particular scenario that I'm trying to emulate and, being fairly new to Cocoa Touch, I'm not sure of the best way to accomplish it. Pardon my lacking tactical knowledge; hopefully some clear exposition will help.
What I'd Like To Emulate:
The app I'm looking at (in particular) is Beat. Below is an example of one of their UIViews - in particular, notice the gear icon for Settings at the bottom.
When that gear is touched or swiped up, two primary UIView changes occur:
The original UIView is slid up the screen about 90% of the way (the key point being that it does not slide all the way up).
A new UIView is slid up to fill that newly vacated 90% space.
This is the basic functionality that I would like to accomplish.
Implementation Idea #1: Single UIViewController w/ Multiple UIViews
At first, I considered having a single UIViewController manage both the "main" and the "settings" views. In that case, it would be a fairly simple thing to transition these views in the appropriate manner.
That said, this seems a bit cluttered to me. Depending on how robust my two sets of functionality are, that's a recipe to overload a single UIViewController. You might tell me that that's okay, but off the bat, it seems too much.
Implementation Idea #2: Multiple UIViewControllers Within Custom Container ViewController
This is the route I'm currently going down. It separates the two discrete sets of functionality into separate UIViewControllers (contained within a Container ViewController) and transitions between the two via:
- (void)flipFromViewController:(UIViewController *)fromController
toViewController:(UIViewController *)toController
{
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
fromController.view.frame = CGRectMake(0.0f, 0.0f, width, height);
toController.view.frame = CGRectMake(0.0f, height, width, height);
[self addChildViewController:toController];
[fromController willMoveToParentViewController:nil];
[self transitionFromViewController:fromController
toViewController:toController
duration:0.5f
options:UIViewAnimationOptionTransitionNone
animations:^(void) {
fromController.view.frame = CGRectMake(0.0f, -(height - 100.0f), width, height);
toController.view.frame = CGRectMake(0.0f, 100.0f, width, height);
}
completion:^(BOOL finished) {
[fromController removeFromParentViewController];
[toController didMoveToParentViewController:self];
}];
}
The problem with this is the transition: it doesn't seem to stop "90% of the way". It looks more like it's intended to completely transition out an "old" controller and in a "new" controller, even though my frame adjustments on the two UIViews are not supposed to be "complete" moves.
Where I'd Like Guidance
I'm not asking for a complete solution - your expertise would be too expensive. :) That said, being fairly new to this, I would love your insight on what the right approach would be. Please let me know if I can provide further information.
Thanks!
I do think your 2nd method is on the right track, and your intuition about using transitionFromViewController:ToViewController is also right -- I wouldn't use that method if you want both view controllers to be present and active. So, I would have the controller with the gear view be a child view controller of a custom container controller, then add the second child off screen to the bottom like you have. Then animate both views up using animateWithDuration:... At the end of that, animation, you should have what you want, and you container controller will have two children.
My app needs to save an image to disk. I do this in a separate thread, so the UI is still responsive, BUT, I do not want the user to add a new image until the first one is saved (about 1 second.)
At the moment, I'm disabling the 'take another picture' button and greying it out, but I'm wondering if there is a method that will disable the whole view, greying out the buttons and darkening the background, like what happens when a UIActionSheet is presented.
I've looked through the UIView docs and don't see anything like this, but it seems like such a useful pattern that is frequently used by Apple that I figured I'd ask, just in case there was such a thing.
Obviously I could do it manually, but why reinvent the wheel if its already part of the API.
TIA: John
set whatever view (main view, subview, etc.) you want to appear disabled to
view.userInteractionEnabled = NO
and also
view.alpha = 0.3f
and maybe even
view.backgroundColor = [UIColor grayColor]
to boot. These last two can be animated, b.t.w.
Present another view with the shadow and the gradient etcetera over this view thus giving it an effect of graying out with shadows. You may even create an image if you know your photoshop. Just show that image on a UIImageView over this view to be blocked. Give the image some nice translucency, shadows etc etc