I'm having a problem about animation.
In View Controller, I have a contentView with frame (0,0,320,200). From View Controller, I pressed a button to open the camera and take pictures from there. Then I dismissed the camera view.
At the moment, I set animation for contentView with new frame (0,200,320,200), but it doesn't work in this case. This is my animation code after dismissing:
[UIView animateWithDuration:0.1f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
_contentView.frame = CGRectMake(0,200,320,200);
}
completion:^(BOOL finished){
}
];
Related
I have a view that acts like the macOS dock - it can be moved offscreen entirely.
My gesture recognizer looks like:
-(void)swipeDown:(UISwipeGestureRecognizer *)sender
{
NSLog(#"Swipe Down");
// this should move the dock 10 pixels below the bottom of the screen
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{[self dockView].frame = CGRectMake(kSafeMarginHorizontal, self.view.frame.size.height + 10, self.view.frame.size.width - (kSafeMarginHorizontal * 2), 80);}
completion:nil];
}
I am only using an autoresizing mask on my dockView with right and left edges pinned. In my main parent view I call:
[[self view] setTranslatesAutoresizingMaskIntoConstraints:YES];
This works fine, but after sliding offscreen, the corresponding Swipe Up gesture no longer works and if I swipe down again, I no longer get the NSLog indicating the method was called.
I can prevent this by not sliding the view entirely offscreen. If I leave a least a few pixels on the screen, it continues to work ok.
Why does this break my gesture recognizer?
It seems that tvOS does not like it when a focused button ends up offscreen. I have also changed this to animate by changing constraints. The key is calling setNeedsFocusUpdate at the end of the animation.
// flush pending layout operations, then animate the constraint change
[[self view] layoutIfNeeded];
[UIView animateWithDuration:0.25
delay:0.0
options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
animations:^{[[self dockViewConstraint] setConstant:1080];
[[self view] layoutIfNeeded];}
completion:^(BOOL finished){
// Do some cleanup after animating.
[self setNeedsFocusUpdate];}];
Is there any way to fade a bar button item, as there is no .alpha attribute to set. I'm interested in fading a button out and fading another button in to take its place on the navigation bar. Is there any way to do this?
EDIT: I am trying to fade the top right Bar Button Item
I understand fading is usually accomplished with the .alpha as I stated before.
My issue is for a Bar Button Item there is NO alpha attribute.
As seen here:
As opposed to a normal button where there is an .alpha attribute:
How can I fade a Bar Button Item?
Easy. You would have to create an outlet for them both then create if statements or whatever method you want to initiate the fade in/ fade out animations:
- (void) animateButton {
button1.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
button1.alpha = 1;
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
button1.alpha = 0;
[UIView commitAnimations];
}
swift
viewDidLoad {
self.button1.alpha = 1
self.button2.alpha = 0
}
When you call Animation Code:
UIView.animateWithDuration(1.0, animations: {
self.button1.alpha = 0
})
// Changing buttons based on UIControlState: You can also do this in storyboard by dragging a bar button item to your view controller and ctrl+drag to your .h file to create an outlet and then commit your animations or code based on what you want.
UIImage *backButtonImage = [[UIImage imageNamed:#"button_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
in my viewcontroller entered all the objects in a scrollview. One of the buttons inside the scrollView creates an animation.
The scrollView get off the page -80.0 orgine.y
So far so good .. Now I want that when you click on the button the scrollview and then goes back down to -80.0 to +80.0 automatically returning to its original position so ... Can you tell me the best method for you to have this?
This is the action that fulfills my button when pushed ...
- (IBAction)AcceptFriendRequest:(id)sender {
PFObject *SelectedUser = [self.UtentiInAttesa objectAtIndex:[sender tag]];
[SelectedUser setObject:#"Confermato" forKey:#"STATO"];
[SelectedUser saveInBackground];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
FFScrollView.frame = CGRectMake(FFScrollView.frame.origin.x, (FFScrollView.frame.origin.y - 80.0), FFScrollView.frame.size.width, FFScrollView.frame.size.height);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
}
In your button event handler
- (IBAction)myBtnClicked:(id)sender {
// Create new CGRect indicate place where you would scroll to.
// Assume it is called `originalRect`
// Use the following method, it should work
[FFScrollView.scroll scrollRectToVisible:originalRect animated:YES];
}
I have this app that has tabs and each tab's root view controller is a navigation controller. I want to display my splash screen or launch image while the app is busy parsing JSON and loading it up in my core data stack and remove it from superview using a fade out animation. I tried this code to make it work but I'm stuck since the image is only displayed on the view inside the navigation controller. What I wanted is to view it full screen with the status bar on top like what you see when launching an app.
_launchImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
if (kFourInchDevice) {
_launchImageView.image = [UIImage imageNamed:#"Default-568h#2x.png"];
}
[self.view addSubview:_launchImageView];
[self.view bringSubviewToFront:_launchImageView];
And this is my code when dismissing it:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(launchImageFadeAnimationDidFinished)];
_launchImageView.alpha = 0.0;
[UIView commitAnimations];
- (void)launchImageFadeAnimationDidFinished
{
[_launchImageView removeFromSuperview];
}
Any ideas on how to do this? Thanks!
I think you are having problem of hiding NavBar in splash screen isnt it ?
Just Add one extra ViewController in your story board.
Then under Utilities ( left side bar ) under Attribute Tab - View Controller make VC initial View Controller.
Call following in your View Did Load
- (void) hideNavBar {
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.hidden = TRUE;
}
Then when you you finish your json parser -
#pragma mark - Delegates
#pragma mark JSON Request
-(void) connectionReady; {
NextVC *viewController = [self.storyboard
instantiateViewControllerWithIdentifier:#"NextVC"];
[self.navigationController pushViewController:viewController
animated:YES];
}
Then finally in NextVC
- (void) showNavBar {
UINavigationBar *navBar = self.navigationController.navigationBar;
navBar.hidden = FALSE;
}
How can I animate the movement of a label or image? I would just like to make a slow transition from one location on the screen to another (nothing fancy).
For ios4 and later you should not use beginAnimations:context and commitAnimations, as these are discouraged in the documentation.
Instead you should use one of the block-based methods.
The above example would then look like this:
[UIView animateWithDuration:0.3 animations:^{ // animate the following:
myLabel.frame = newRect; // move to new location
}];
You're looking for the -beginAnimations:context: and -commitAnimations methods on UIView.
In a nutshell, you do something like:
[UIView beginAnimations:nil context:NULL]; // animate the following:
myLabel.frame = newRect; // move to new location
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
Here is an example with a UILabel - the animation slides the label from the left in 0.3 seconds.
// Save the original configuration.
CGRect initialFrame = label.frame;
// Displace the label so it's hidden outside of the screen before animation starts.
CGRect displacedFrame = initialFrame;
displacedFrame.origin.x = -100;
label.frame = displacedFrame;
// Restore label's initial position during animation.
[UIView animateWithDuration:0.3 animations:^{
label.frame = initialFrame;
}];