iOS7 - Why is CGAffine Transform working properly on iOS8 but not iOS7? - objective-c

I am having a problem when using CGAffineTransformMakeTranslation on iOS7. The view I am using the CGAffineTransformMakeTranslation is going to a different position when running iOS7 and iOS8. Why is this and what am I doing wrong?
I have a view that I am calling "hud" that is the length of its parentView and 125.0 tall. I am using Auto Layout and here is a screenshot of my story board so you can see how I have the constraints set up. The container view is a collection view of photos.
I have the "hud" hide right away with a transform downward and when a photo is selected it will slide back up into view.
-(void)showHud:(BOOL)show
{
NSLog(#"Frame Height: %f", hud.frame.size.height);
if (show && !hudSelectionMode)
{
[UIView animateWithDuration:0.5 delay:0 options:0
animations:^{
hud.transform = CGAffineTransformMakeTranslation(0, 0);
hud.alpha = 0.8f;
}
completion:^(BOOL finished){
}
];
}
else if (!show && !hudSelectionMode)
{
[UIView animateWithDuration:0.5 delay:0 options:0
animations:^{
hud.transform = CGAffineTransformMakeTranslation(0, hud.frame.size.height);
hud.alpha = 0.8f; // will be 0.0 when not testing
}
completion:^(BOOL finished){
}
];
}
}
Here is the problem
On iOS8 this works flawlessly the hud is hidden from the start and will slide up when an image is selected:
However when running on iOS7 devices the hud is not where I would expect it to be:
If I comment out all the code in -(void)showHud:(BOOL)show the hud will sit at the bottom of the parentView where I would expect it to on both 7 and 8.

On iOS7 you need to multiply the translation value by the scaleFactor of the device. On iOS8 this seems to be done automatically, but not on iOS7.

Related

Animating AutoLayout constrains breaks in iOS 9

So I just upgraded xCode to Version 7.0 (7A220) and it broke some animations, I'm not sure whats wrong here.
[UIView animateWithDuration:SLIDE_UP_DURATION animations:^{
self.cubeIconWhiteYAlignmentToContainerView.constant = actualOffset;
[self.cubeNoIconWhiteImageView layoutIfNeeded];
[self.cubeIconWhiteImmageView layoutIfNeeded];
self.buttonConstraintToBottom.constant = FINAL_BUTTON_HEIGHT;
[self.logInButton layoutIfNeeded];
[self.registerButton layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
[self fadeIn];
}
}];
the buttons slide up just fine but the image views snap to their final height. What am I missing is this just a bug on apples side?
So Apparently both views that the constraint touches need layoutIfNeeded called.

Setting UIButton's title cancels animation

I am not familiar with iOS animation, and here is my problem:
On the login screen of our app, there is a login button. When that button is clicked, we need to move it up then change its title. Moving it up is animated like this:
[UIView animateWithDuration:0.5
animations:^{
loginButton.frame = newLoginButtonFrame;
}
completion:^ (BOOL finished) {
}];
This works as expected.
Then after we try to change the title in the completion callback like this:
[UIView animateWithDuration:0.5
animations:^{
loginButton.frame = newLoginButtonFrame;
}
completion:^ (BOOL finished) {
[loginButton setTitle:#"Cancel" forState:UIControlStateNormal];
}];
something weird happens: the button "jumps" back to the original position as if the animation was cancelled.
What is going on here?
If you are using auto layout you should animate the constraints not the frame. For example you can set an outlet for the bottom constraint and animate like this:
viewBottomConstraint.constant = 32;
[UIView animateWithDuration:0.5
animations:^{
[self.view layoutIfNeeded]; // Called on parent view
}];
}
You can find more information in the documentation here

Animating with Auto Layout and iOS7 jumps to end of animation (fine in iOS6)

I am using Autolayout and animating by changing the constraints, however, in iOS7 the view simply jumps to the end position - in iOS6 I get a nice animation.
Is should be noted these views are UICollectionViews and I have checked the Storyboard and there are no Layout errors.
All I can think is there is something and am or am not setting on the Storyboard or something that I am doing wrong with the Constant settings in the Storyboard.
primaryMenuYContraints.constant = BUTTOMX;;
leftMenuYContraints.constant = 136.0f;
leftMenuBottomConstraint.constant = 5.0f;
[UIView animateWithDuration:0.7f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^
{
// Move in menus
[self.primaryOptionCollection layoutIfNeeded];
[self.menuOptionCollection layoutIfNeeded];
}
completion:^(BOOL finished)
{
}];
I changed to and now works in both iOS7 and 6, still not sure why it does/did it though! I still think I am setting something up wrong in the Storyboard. I am add another view (nothing to do with this lot) programmatically so I believe that is based around frames until I convert it (which I am not doing).
primaryMenuYContraints.constant = BUTTOMX;;
leftMenuYContraints.constant = 136.0f;
leftMenuBottomConstraint.constant = 5.0f;
[UIView animateWithDuration:0.7f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^
{
// Move in menus
[self.view layoutIfNeeded];
}
completion:^(BOOL finished)
{
}];

Scaling UIView using transform after animating frame change causes UIView to jump back to original frame before scaling

I'm trying to scale a UIView (with animation) after I move it (with animation). The problem is, when the scaling animation begins, it jumps back to the original position. Why?
[UIView animateWithDuration:t delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
// Drop the ball
CGRect frame = coinView.frame;
frame.origin.y += d;
coinView.frame = frame;
coinView.shouldSparkle = NO;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
// Initial scale up for ball "poof"
coinView.transform = CGAffineTransformScale(coinView.transform, 1.5, 1.5);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
coinView.transform = CGAffineTransformScale(coinView.transform, 0.000001, 0.000001);
} completion:^(BOOL finished) {
[coinView removeFromSuperview];
}];
}];
}];
EDIT: This is how I generated my d:
static CGFloat groundPositionY = 325;
CGRect convertedFrame = [coinView.superview convertRect:coinView.frame toView:self.view];
CGFloat d = groundPositionY - CGRectGetMaxY(convertedFrame);
EDIT2: Okay, so I changed the second UIView animation to the following and I discovered that the jump (and the scale down) happens before the second animation occurs, i.e. when animateWithDuration:delay:options:animations:completion: is called.
[UIView animateWithDuration:5 delay:3 options:0 animations:^{
coinView.transform = CGAffineTransformScale(coinView.transform, 1.5, 1.5);
} completion:nil];
I tested your code and it works fine for me. How do you generate your d? and on which block exactly it goes back?
I found the problem...
The coinView is a subview of a child view controller's view. The problem comes from the fact that I overrode that child view controller's viewDidLayoutSubviews method to lay out all the coinView's, so whenever that method was called, the coin view would move back to its original position and size intended by the child view controller.
Thanks for all of your help, repoguy and sergio!!

UINavigationBar Fade Position Problems

So, here's an interesting little problem I've had to deal with. I coded a navigationBar to be translucent and the view underneath to be fullScreen. When I load the view, I can tap on a clear button in the view to "activate" an animation that fades in the bar and other ui elements.
When I rotate the device WITH THE UI ELEMENTS VISIBLE it works perfectly.
But if I tap again to "turn off" the elements with a fade out animation, then rotate, it pushes the naivgationbar up into the status bar.
I don't understand why this happens. I don't want to turn off the statusBar, but if I have to, I will. Can anyone help me with the bar's autorotation positioning?
EDIT SOLVED
SOLVED, this code animates the 20 pixels needed to move the bar down.
- (void)showToolbar
{
if (toolbar.hidden == YES)
{
[self.navigationController.view layoutSubviews];
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
toolbar.hidden = NO;
toolbar.alpha = 1.0f;
self.navigationController.navigationBar.alpha = 1.0f;
CGRect frame = self.navigationController.navigationBar.frame;
frame.origin.y = 20.0;
self.navigationController.navigationBar.frame = frame;
}
completion:NULL
];
}
if ([self.navigationController.navigationBar isHidden]) {
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
}