UIViewAnimationTransitionFlip and force refresh - ios

I have to do a flip transition between to view with uiwebview. (Flip by the time second webview load url)
My problem are that my second webview stay black till the transition was finish. (no refresh during the transition).
Is there a way to force a loading\refresh during the transition?
[UIView transitionWithView:mysuperview
duration:0.75
options:UIViewAnimationTransitionFlipFromRight
animations:^{
[myview removeFromSuperview];
}
completion:nil];

You would want to look into methods like setNeedsDisplay within the UIView class. I recommend checking out Drawing and Updating the View section of the UIView class which could be found here. Overall, views do not know when they need to refresh themselves so you will need those methods.

Related

Navigation drawer- sliding issue in ios

I am trying to create a sliding menu (like the one in google maps app) in which menu screen should be shown or added as subview over the existing screen on tapping a button. While showing it, the sub view should be animated from left to right. I tried to animate while adding it as subview, but failed in doing so. Can any one suggest how to do it? (or) Can I do it using navigation controller?
Thanks in advance!!
You need to add the subview, and set it's frame out of the screen.(320,0,100,568 for example).
Of course it's better to use auto layout for that.
Add as subview:
[self.view addSubView:sideMenu];
When you want to show it, just change it's frame using animation block.
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
sideMenu.frame = CGRectMake(220,0,100,568);
} completion:^(BOOL finished) {
}];
As I said, it's better to use auto layout and not setting frames. I did it only for the example.

Autolayout - Compressing UINavigationController at the same time as pushing a new view controller

I am working on an iOS app. The root view controller contains a UINavigationController which wraps up the main contents of the app, and a footerViewController (audio player) that will compress the main content when it animates up into view.
I’m using auto layout to show and hide this footer like so:
_footerVisibleConstraints = [… #“V:|[navControllerView][footerView(==90)]|" …];
_footerHiddenConstraints = [… #“V:|[navControllerView][footerView(==0)]|" …];
Generally this works well. But I’m struggling with one issue. I have a situation where I need to push a new view on the UINavigationController stack and animate my footer into view the same time:
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.5f animations:^{
[[self view] removeConstraints:_footerHiddenConstraints];
[[self view] addConstraints:_footVisibleConstraints];
[[self view] layoutIfNeeded];
}];
[navigationController pushViewController:newViewController animated:YES];
The problem in this situation is that newViewController is animating in snapped to it's final (compressed) state, and not beginning from the full starting height of the view. So there is a gap at the bottom while the footer animates in.
I’ve slowed down the animation and posted a video here to demonstrate what I am describing.
Also, notice how when I pop back to the root view controller the content in the UINavigationController isn’t compressed either.
So, can someone explain to me what’s going on here? Is there a way to accomplish what I am after?
Just add a variable to the .h of your VC to stipulate whether the footer needs to open or not. Then add the footer animation to the didAppear method with a check on the variable. This will result in performing the actions in the order you want them to happen.
If you want both animations to happen at the same time you will need to subclass a segue and add a custom animation.

UIScrollView Jerky Scrolling

I have a big scroll view. I just wish to scroll around the scroll view with fixed steps on every button press. However when I write the following code the scroll view scrolling is very jaggy. Can someone explain why?
CGPoint lstructCurrentPoint = self.objScrollView.contentOffset;
lstructCurrentPoint.x += 400;
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,
lstructCurrentPoint.y,
self.objScrollView.bounds.size.width,
self.objScrollView.bounds.size.height)
animated:NO];
} completion:^(BOOL finished)
{
}];
I do not use the animated:Yes arguement because I need custom scroll speeds between the different contentOffsets.
when you update your scroolview content frame while scrolling with an animation is like you try to update something that is in the past that is already changed... (probably is not the best explanation :D )
try with this in your animation option:
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState
Why don't you just try using
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x, lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
instead of using this within UIView animation function.
Try to use
[self.objScrollView setContentOffset: CGPointMame(lstructCurrentPoint.x, lstructCurrentPoint.y) animated: YES];
instead of scrollRectToVisible.
scrollRectToVisible animated is an animation by itself.
With your current code, you are trying to animate the animation.
Hence it is jerky.
Just use to scroll the rect to visible:
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
No one can properly answer your question without knowing what content you have in the scrollView.
However, you can find out what is causing this yourself.
Profile the app on your device. This will open Instruments. Select the Core Animation tool.
When the app is running scroll the view so that instruments captures the data.
Now the Time Profiler section will tell you exactly what is taking a long time. Fix this and you'll have smooth scrolling.

fade in/fade out UISegmentedControl in XIB

I have a UISegmentedControl set up in my XIB. I want it to appear on viewDidLoad and if the user taps the area of the screen it's in, and then to disappear if the user taps it again or to fade out if the user leaves it alone.
In looking around for how to manage this I've found a lot of stuff about fading UIViews, but not as much on fading individual subviews, and little at all on fading elements in the XIB. I tried to adapt the UIView stuff but failed.
How can I make this work?
EDIT: Okay, I've got the appearance at viewDidLoad and the fade out working. But when the user taps the area where the UISegmentedControl is (now invisible because alpha=0), nothing happens. This is the code I'm using:
- (IBAction)tapInvisibleSegContr
//This is connected to the UISegmentedControl with the action Touch Up Inside. Until now, the segmented control has been at alpha=0 since fading after viewDidLoad.
{
self.segContrAsOutlet.alpha=1.0;
[self fadeMethodThatWorksInViewDidLoad];
NSLog(#"Yup, tapped.");
}
I'm not even getting the NSLog. I've got the action hooked up to the UISegmentedControl, with the action Touch Up Inside. What am I missing?
If it is resident in a xib, just put his alpha to 0, do the properly connections: an Outlet and an IBAction for value changed
Then in the viwDidLoad right after [super viewDidLoad] write:
[UIView animateWithDuration:1 animations:^{self.mySegOutlet.alpha = 1;}];
Inside the IBAction right after you code the answer before the last } write:
[UIView animateWithDuration:1 animations:^{self.mySegOutlet.alpha = 0;}];
This is the easiest method.
Bye
In the xib set your control's alpha to 0.0, then use UIView animation methods to animate its alpha to 1.0. For example:
[UIView animateWithDuration:1.0 animations:^{
self.segmentedControl.alpha = 1.0f;
}];
EDIT: To your problem with not getting the action called, try attaching it for the value changed control event - I don't think UISegmentedControl sends for touch up inside.

I would like to use transitionFromView to flip in a new view and have my uiswitch that is on the second page, already be set, is this possible?

Edit: just to be clearer on what I am looking to do. I have 1 view with button on it. When you press the button a new view transisions in with a flip. On the new view their are two switched that I set through code after the user has clicked the button. What I want to happen is that the switches are in their final spots, before the new view flips in. What happens is the new view flips in, and then the UIswitches flicker into place.
This is the code I have. I have tried setting the uiswitch on viewwillappear and viewdidload, but each time it comes over with the default setting from IB and switched after the UIview transition is complete. I want the switch to be set already, so that once the view "flip" is done, there is no more movement on the screen. Thanks.
//set the uiswitch before the transision
[self.settingsPage.myUISwitchThing setOn:NO animated:NO];
//transition by flip
[UIView transitionFromView:self.view toView:self.settingsPage.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL done ) {
[self.view removeFromSuperview];
Looks like the issue was that I was trying to animate the switch movement when I was setting the switch value in the viewdidload. setting animated:NO has resolved the issue in the iPhone simulator. hopefully it will fix it on the device when I can test it at home later.

Resources