There a lot of similar questions with answers. For example:
link
but almost all of them are unsuitable because I also want to perform something like this:
button1.frame = button2.frame;
button2.hidden = YES;
So if I use an example with beginAnimations: then I can see how button1 changes its frame (it moves while app perfoms a transition animation).
How to solve this issue? First of all should I set a button frame in another way or should I find another code for transition?
EDITED
Additionally I have found out that not all ways allow to show fade animation I need so I have edited my question a little.
link
The best solution from it is animating way which works for my case.
The most strange thing is to disable view controller's own animation instead of its changing.
Related
Update
The animation is working for setEnabled=NO.
The animation for setEnabled=YES is being triggered when UIScrollView is scrolling, the UIButton is inside the scrollview and the animation for setEnabled=NO is being triggered when UIScrollView is done scrolling.
So, I think the reason why animation for setEnabled=YES is not working is because the view is moving. I am not sure but this seems to be the only logical explanation from what I have found so far. I did a test with dispatch_after() and the animation worked for setEnabled too, in other words the animation is working if it is being triggered when the view is not moving.
What I need to do ?
I have two different background images for UIButton one for UIControlStateNormal and another for UIControlStateDisabled.
I want a effect where UIButton slowly transitions over from one state to another
What have I been doing ?
BOOL enableDisable = YES;
[UIView transitionWithView:((UIButton*)object)
duration:3.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{ [((UIButton*)object) setEnabled:enableDisable]; }
completion:nil];
The Problem
UIButton transforms to setEnabled=NO state over the duration but no matter what I put in the options setEnabled happens almost instantly.
is there something I am missing ?
Thanks in advance for your time and response.
Unfortunately, enable or disabled state for UIView aren't part of animatable properties in apple docs. The animatable properties are:
frame, center, bounds, transform, alpha, backgroundColor, contentStretch
Reference here: UIView animation
However if you want to create custom property for animation, you can have a look at this post which describes a way to achieve it. Create a custom animatable property
I can confirm that your code works as expected both for the transition
enabled: NO -> YES
and for the transition
enabled: YES -> NO
So, my guess is that something else is happening in your app that somehow interferes with the transition. Try defining a completion block like:
...
completion:^(BOOL finished) {
NSLog(#"FINISHED? %#", finished?#"YES":#"NO");
} ];
and add a trace log before the transitionWith call or inside the animation block to check how long the transition runs from start to completion.
My guess is that while the button is transitioning something else is happening that changes its state and as a secondary effect breaks the transition. I fear that without seeing more code, it will not be possible to help you further...
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
Anybody have any idea how this is done?
http://youtu.be/r_cII4_aq_A
In general, the idea is awesome, but I would like to know how to do each specific thing. In the video, the pages are being swiped too fast so you can't see, but as you transition from one page to the next, each pixel smoothly transitions to it's new color. Also, it's really cool how the icon gets smaller to a minimum size as you transition away from a screen.
Maybe there's some 3rd party library that provides a protocol and it's relatively easy to implement, but I can't find it. If there's not, I'm thinking it's just one view controller with many views side by side and as you drag your finger, it calculates where each view needs to be..and what color every pixel needs to be.
I imagine you already have it by now. But in case you still have any doubts, I made gist that does the animation: https://gist.github.com/mnmaraes/9536364
Anyways, have fun.
It's a fade animation, so:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
_backgroundImageView.image = nextImage;
} completion:nil];
should do the trick for the background part.
For the foreground/icon part you can animate the transform to scale and translate the views as they slide in and out.
So, I have a setup where an UIPopoverController presents information at the cursor in a text view. When the cursor moves, I present it again. But this is jarring, and I'd like for the popover to move in a smooth, animated fashion. Will I really have to do that manually by using a series of presentFromRect calls, or is there a better way?
Unfortunately UIPopovers are not designed to be moved around like that.
The only way to do that without presenting it all over again is to write your own UIPopover replacement and animate its position using the standard CAAnimation or UIKit animation techniques.
If think you cannot do that without use presentFromRect. But if you really want to do this, create your own. Recreate the look of a popover controller using a UIView and track the touches. You can use an alternative like WEPopover.
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