I'm currently flipping a UIImageView using UIView transitionWithView: duration: options: animations: completion: and switching the image inside the animation block. One of the two images it's switching between is landscape and the other is portrait so its also rotating and resizing the imageview so they both fill the screen.
What I can't figure out is how to animate the flip, and rotate it at the appropriate time but not animate the rotation. Is there a way to do this?
You might also try putting the change you don't want to be animated inside a CATransaction begin/commit, with setDisableActions:TRUE. (inside your animation block.) I don't know if it would work or not, but it would be worth a try.
Related
I am trying to get an animated image in a canvas to animate, but I don't believe that sprite rendering works with canvas'. Ive tried adding an animation component to it however I need the image to have the controller on it, as it's animation changes all the time. How would I be able make the UIImage animated whilst still using the Animation controller
You need to create an animation using Animation View and selected UIImage - Animation View will let you change UIImage sprites, position and more.
Then simply drop that animation into your Animation Controller and create whatever transitions you want.
Here you can read more about it:
Animation View Documentation
I have a prototype cell and I put a UIVisualEffectView inside its ContentView. Visual Effect View's Blur Style is Dark and Vibrancy is off. Then I set the alpha of the Visual Effect View to 0,5 using the IB.
Then on runtime, I get a warning that says:
<UIVisualEffectView ...> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
I couldn't understand why this warning is there and how I can set this alpha property properly.
The question is what do you want to animate. If it's the effect, you cannot animate it via the alpha property. However, since iOS 9, you can animate it with setting the effect in animation block.
UIVisualEffectView* view = [[UIVisualEffectView alloc] initWithFrame:self.view.bounds];
view.effect = nil;
[UIView animateWithDuration:0.3 animations:^{
view.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}];
Alternatively, you can animate the effect by animating the alpha of the wrapper view, as proposed in the other answers (working even on iOS 8).
If you want to animate the content of the visual effect view (the subviews), animate the contentView property instead (which you should use to add subviews of the effect view).
[UIView animateWithDuration:0.3 animations:^{
view.contentView.alpha = 1.0;
}];
So to sum up, you should never change alpha of the UIVisualEffectView itself as it's most likely not what you want.
As far as I can remember you cannot change the alpha of a visual effect view. The alpha always has to be one.
The desired effect can be achieved by setting alpha of the background color rather than the Visual Effect View. The subviews should be added to View of Visual Effect View and they are not affected by the background blur.
The Vibrancy effect must be selected in View Effect View options above.
See image:
user1179321 definetely right. According to UIVisualEffectView Documentation;
When using the UIVisualEffectView class, avoid alpha values that are
less than 1. Creating views that are partially transparent causes the
system to combine the view and all the associated subviews during an
offscreen render pass. UIVisualEffectView objects need to be combined
as part of the content they are layered on top of in order to look
correct. Setting the alpha to less than 1 on the visual effect view or
any of its superviews causes many effects to look incorrect or not
show up at all.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIVisualEffectView/index.html
My solution:
Duplicate the layer behind the visual effect view. (In my case an UIImageView)
Animates the alpha value the the duplicated view. (e.g. alpha form 1 to 0, shows the blurred Image)
If u presenting viewcontroller modally, try to disable animation checkbox in segue.
You never know if the delay is long enough; so a bit of a cleaner solution is to just do the presentation in the next run loop.
dispatch_async(dispatch_get_main_queue(), ^(void){
[self presentViewController:yourPopoverr animated: YES completion: nil];
});
I've got a UIView with a UILabel on top. I have the UILabel's content mode set to 'UIContentModeLeft'. As expected, when I animate the frame of the UIView to be smaller than the original size, the label 'jumps' to the final frame without animating nicely.
As far as I can see, UIContentModeRedraw does not force 'drawRect' to be called on every 'animated frame'. I've tried using a custom CALayer as well but can't seem to cause the frame to resize smoothly.
Is there any way to do this? The animation as it stands is extremely glitchy. UIContentModes are not useful and I can't use a frame for contentStretch as well as none of the edges of the label can be stretched. What I really need is a 'refresh' of the label every time the parent view resizes.
There's no way of doing this unfortunately, so I've learnt. The only other way is to actually run a timer that updates the frame every time it's invoked. This results in a very jerky animation given a resize of a complex view is time consuming. I ended up achieving the same thing with some pre-rendered onscreen elements and a whole lotta 'magical effects' behind the scene.
I have a tableView. Instead of having multiple subviews in each tableViewCell , i have added one main subview which draws each of the other subviews in its drawRect method.
(I have read somewhere that this makes scroll animation look better. Also apple has a sample project CustomTableViewCell).
First , problem is when i changes the orientation of device, then drawRect does not call automatically. And each tableviewcell appears to be stretced.
I solved this by using
mainView.contentMode = UIViewContentModeRedraw
This solves the problem. Now when the orientation change is done, drawRect is called automatically .
But during the orientation change, the animation of rotating view still shows each tableview cell stretched. It is a very small thing, but still it is noticeable. Can anyone suggest something on this ?????
You can't redraw during animation (not easily, anyway).
Split the table cell into components again and setup autoresizing correctly. The animation will then animate only component positions and it will look fine.
Where did you read drawRect: would make scroll animation better? Did you have some problems with scrolling animation?
Edit:
IMHO There is no way how to fix resizing animations and keep the performance increase from using drawRect: instead of subviews.
When you tap the bookmark, it slides down or up smoothly. As it slides up, it disappears as if behind the view directly above it. I know how to animate changing the frame of a view, but I don't know how to make it disappear like that. (I don't want to resize the UIImage, just slide the UIImageView up and out of sight.)
I figure I need an invisible button to toggle the animation, and an UIImageView to animate. Do I need to change the bounds of the UIImageView, or should I use the frame? I thought I could just change the height from X to 0, but it didn't seem to resize the UIImageView. I had a little luck with settings the bounds with clipping subview's enabled, but I wasn't quite there.
I don't think I understand the relationship between the bounds and the frame.
I ended up adding a parent UIView to contain the UIImageView. It has the dimensions in which I want the UIImageView to be viewable in, and then I just animate the frame so the Y dimension is equal to the negative height and it slides up nicely.
I was on the wrong track with the bounds.