UITableView contetOffset and swipe starting point not working together - objective-c

I'm using the following code in a button tap to move my table view up, but when the user swipes the table view down it gets to the original place. How can I solve it?
[UIView animateWithDuration:0.3 delay:0 options: UIViewAnimationCurveEaseOut
animations:^{
self.tableView.contentOffset = CGPointMake(0, 59);
}
completion:^(BOOL finished) {
if (finished) {
self.tableView.contentOffset = CGPointMake(0, 59);
}
}
];
Any tips?

They might have changed this in newer iOS releases, but I remember that UITableViewController doesn't play well with a custom defined tableView frame.
I'm pretty sure it will work correctly if you use a regular UIViewController.

I'm not sure about the syntax; but you should be able to define your own custom gesture. Which will handle a particular function. It should allow you to actually create your own event handler and view.
Which should allow you to control how it scrolls throughout to the position.
The article is here: http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html
If I'm misunderstanding what your trying to accomplish I apologize, hopefully this helps though. If not I'm sure a more seasoned developer will be able to assist you.

Related

no animation when using modal segue

I have a view controller and have a few objects that I have some simply animations hooked up to.
[UIView animateWithDuration:0.25
delay: 10.1
options: UIViewAnimationOptionCurveEaseIn
animations:^{
addNameViewConstraint.constant = 10;
addNameView.alpha = 1.0;
[self.view layoutIfNeeded]; // move
}
completion:nil];
[UIView animateWithDuration:0.25
delay: 0.15
options: UIViewAnimationOptionCurveEaseIn
animations:^{
addEmailViewConstraint.constant = 10;
addEmailView.alpha = 1.0;
[self.view layoutIfNeeded]; // move
}
completion:nil];
When I was using the push segue the animation works fine. But when I switched to using a modal segue the animation stopped working. I increased the delay in the first one to 10.2 seconds thinking that maybe it was animating before I got to see it. I am calling this animation in the viewWillAppear method. Again works if I'm doing a push segue.. but not for modal. Any ideas?
I am calling this animation in the viewWillAppear method
This is a common mistake. viewWillAppear: is too soon to start the animation. The view has not yet appeared so there is nothing to animate. Move the animateWithDuration:... code to viewDidAppear: and all will be well.
This is, however, as you say in your comment, insufficiently satisfying. What you are after is that the modal transition should be happening and your extra animations within the new view should already be happening as the modal view is in the process of appearing. Instead, with viewDidAppear:, the modal view finishes appearing, it settles into place, and then your other animations start, which is not as cool.
One solution might be to move the animations again, this time to viewWillLayoutSubviews. This is trickier because this method gets called a lot. You will need to use a BOOL instance variable as a flag to ensure that your animations run only once. Thus, this should work (I tried it and it seemed fine):
-(void)viewWillLayoutSubviews {
if (!self->didLayout) {
self->didLayout = YES;
[UIView animateWithDuration:0.25 animations:^{
// mess with constraint constants here
[self.subv layoutIfNeeded];
}];
}
}

UIView animation stop when UIView willDisappear

I am not much into iOS animation. What I am trying to achieve is a simple message view that slide vertical from bottom of screen to a given y, then after few instants the UIView rollback in vertical to go off screen.
[UIView animateWithDuration:0.5f
animations:^{
self.messageView.frame=CGRectMake(x, y -80, width, height);
}
completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5f delay:2.0f options:UIViewAnimationOptionCurveLinear
animations:^{
self.messageView.frame=CGRectMake(x, y + 80, width, height);
}
completion:^(BOOL finished){
// do something...
}
];
}
} ];
This is working fine, but I am having a problem using this mechanism in a iOS UITabBar application: when I change tab, the animation stop, I can infact see that "finished" completion is "false". Therefore the second block is not called, and the message view stays on.
Here are the questions:
my first concern is to understand if the code I have written is correct, regarding the nested animations.
I could solve by ignoring 'finished' and execute code anyway, but I don't feel it is a good idea
within the last completion block, I have put some programming logic, basically I am restoring few UIButtons state, and some other little UI change. At this point I don't know if it is a good idea, it seems not, but how can let the UI knows that the message view has disappeared. NSNotification and KVO seems a bad idea when fast responsive UI change are involved.
You can stop all animations for a layer by sending the layer a removeAllAnimations message.
[sel.view removeAllAnimations];

Detect end of implicit animation when changing the UICollectionViewLayout

I am currently working with UICollectionView and after changing the layout from one to another with setCollectionViewLayout:animated: I want to execute some code upon the completion of the animation. Any idea how to achieve that?
Cheers,
Just for the record, there is now a -setCollectionViewLayout:animated:completion: method on UICollectionView, introduced in iOS 7.
I found that to be able to control the animation, rather than using the implicit one with setCollectionViewLayout:animated: you can use a standard UIView animationWithDuration and change the layout in the animations block, like this:
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
self.oldView.collectionViewLayout = self.otherLayout;
self.newView.alpha = 1.0;
}
completion:^(BOOL finished){
self.oldView.alpha = 0.0;
self.otherLayout = nil;
}];
I don't know if it is the recommended way to do it but it lets you control the animation and execute code upon completion.

why button cannot move in animation?

I want to click _transitButton to call onTransitButtonDidClick to move _rightView.
The problem is the button cannot do as I set self.transitButton.frame = CGRectMake(0, 0, 30, 20);.
update:
_transitButton original frame is (0,280,30,20)
the result is, the button move from the original frame to (0,0,30,20), but quickly move back to original point.
why it went back?
why and how to solve this issue?
- (IBAction)onTransitButtonDidClick:(id)sender {
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationCurveEaseInOut
animations:^{
[_rightView setFrame:CGRectMake(40,0,320,548)];
[_transitButton setFrame:CGRectMake(0,0,30,20];
}
completion:nil];
}
you are using autolayout in your xib and constraints keep the button in place.
with animation it appears to work because the constraints arent evaluated for animations.
so either turn off AUTOLAYOUT for this xib or modify the appropriate constrains.
(I tried this with a small sample app and that's it.)

Customize view controller transition animation timing?

Is there a way I can easily change the duration of the transition animation between view controllers? For example if I call dismissModalViewControllerAnimated:YES can I also give an option to control how long that transition occurs?
Not really. You can, though, tell dismissModalViewControllerAnimated to not animate, and then animate yourself using transitionWithView, e.g.,
[UIView transitionWithView:self.view.superview
duration:2.0
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[self dismissModalViewControllerAnimated:NO];
}
completion:nil];
Obviously, use whatever duration and options work best for you.