UIScrollview setContentOffset and animation - uiscrollview

I want to setContentOffset with different animation transition.
Now I use:
[UIScrollView animateWithDuration:speed animations:^ {
[scrollView setContentOffset:offset];
}];
Can you help me, How I achieve animation during set offset.

I am not quite sure, I understand what you are looking for. However, in the case you are looking for a UIScrollView class whose contentOffset is animated with a non-linear timing function you might take a like at my MOScrollView. I use a CADisplayLink to animate the contentOffset. Though, please note that it might not work perfectly as I did not yet use this class in production.

Related

Animate UIView as flipboard in iOS

I tried to use MPFoldTransition for my UIView animation. But I want it like flipboard. That is, it should be animated as per the user touch.
Please help me that how can I achieve it. Also, is there any other library for UIView animation like flipboard.
If you want to use a library for this flip, MPFlipViewController uses MPFoldTransition and works with a pan gesture.
Also, take a look at https://github.com/ITechRoof/ITRFlipper
If you want to build this yourself and have a true flip like Flipboard (where it flips in the middle, with appropriate shadows), taking a snapshot of the view and using a simple matrix transform can do the trick. I'm not going to go into all the details as I could talk for hours about animation timing and shadows.

How to animate horizontal bar with right cap, by UIView animation in iPhone

I got wiered but unsurprising animation from call UIView animation, I don't know if it works the same by using CALayer animation. I guess it is.
please see this picture: what I want is to animate a horizontal bar growing horizontally, what I do is:
Subclass a UIView, called UIViewBar, and in its drawRect:rect method, I draw the shape of rectangle and a right cap, it's done by
CGContextMoveToPoint A
CGcontextAddLineToPoint B
CGContextAddArcToPoint D
CGContextAddLineToPoint C
//then close the path and fill the context
Then I call this UIViewBar (initWithFrame:rect) in my UIViewController, and the shape is what I want, looks fine. BUT when I perform [UIView animation] say from original rect to rectGrew it does not perform nicely. Instead, it perform as the picture says.
Well, after thinking, it's not totally unreasonable because when the UIView horizontally stretches itself, it does not know the cap will not be changed. So is there another way to do this?
Actually, I'm very new to drawing, graphic, and animation. What I know is that (if wrong please kindly correct me):
If I want to "draw something", I should override the UIView's drawRect method, and this is done by initing the UIView, should not or better not to be called outside. Say I drew a rectangle in a UIView by CGContextFillRect.....
But what if I want to animate this rectangle? I cannot make animation based on Quartz2D, but from UIView animation or CALayer(deeper tech), so What I have to do is to make the rectangle itself as a seperate UIViewRect seperately, so I can call the [UIViewRect animation] method, AM I RIGHT ON THIS
If so, I have to make every rectangle that I want to animate to be UIView respectively. Doesn't it affect performance? Or it is just the way apple prefers to do ?
Any suggestion will be much helpful, GREAT thanks.
Wow, it's the first time that no answer posted at all! TO answer my question: it requires to consider animate custom property of CALayer. The custom property is the AB width (the width without cap width, that should work). If someone wants detailed code. Please google custom property animate in CALayer.

IOS: Animate UICollectionViewCells to slide when changing orientation

I'm looking to override my UICollectionViewFlowLayout to cause the cells to slide when changing positions due to an orientation change. What I have currently is 3 cells per row in portrait and 4 cells per row in landscape but the only animation I can get is the default fading in when I change orientations.
I've been looking at using performBatchUpdates but I'm pretty sure that's not where I'll find the answer.
I've also been looking into the layoutAttributesForElementInRect and layoutAttributesForItemAtIndexPath which I think is where I'll find the answer. I'm not sure if I'll need to create a new attribute for the cells (previousCenter maybe) and use that as the starting point for new animations or maybe use performBatchUpdates using what should be the new frame as the value to change.
For the record all animation questions I've found have been about how to change animations for insertion and deletion of items which is not what I'm wanting to do.
Try
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:( NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self.collectionView reloadData];
}
and then add whatever you need to "slide" it at that point.
If you are using flowLayout or a subclass of it, it should automatically reposition the cells for you.If you subclass layout you might need to adjust the layoutattributes you return to correspond to the rotation. The animation should be done for you though.

Scaling with Core Animation

I have a NSScrollView that I want to scale down 50%. I do this with the below code:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"transform.scale"];
animation.fromValue = [NSNumber numberWithFloat:1.00];
animation.toValue = [NSNumber numberWithFloat:0.50];
[animation setDuration:0.20f];
[animation setFillMode:kCAFillModeForwards];
[animation setRemovedOnCompletion:NO];
[self.scrollView.layer addAnimation:animation forKey:#"drag"];
This works, but the scroll view's document view receives mousedown events when I click outside of the scaled down view. So although the scroll view and its content visually looks scaled down, they technically aren't.
How would I go about doing this?
Thanks!
Layer animation acts exactly as you describe (The animations only change the appearance, not the underlying geometry.)
Try using UIView block animation and change the scroll view's transform rather than the layer's.
EDIT:
Oh. Sorry, I thought this was iOS. I guess I should have noticed that you said it was an NSView, not a UIView. I do most of my work in iOS these days, and my OSX experience is mostly from before the days of Core Animation.
I think the answer is to get the view's animation proxy and set the change on that, but I've only done a few learning exercises with animation proxies in Mac OS, so I'd have to do some digging to look up the specifics.

NSScrollView Zooming of subviews

Apologies for the noob question - coming from an iOS background I'm struggling a little with OSX.
The good news - I have an NSScrollView with a large NSView as it's documentView. I have been adjusting the bounds of the contentView to effectively zoom in on the documentView - and all works well with respect to anything I do in drawRect (of the documentView)
The not so good news - I have now added another NSView as a child of the large documentView and expected it to simply zoom just like it would in iOS land - but it doesn't. If anyone can help fill in the rather large gap in my understanding of all this, I'd be extremely grateful
Thanks.
[UPDATE] Fixed it myself - 'problem' was that autolayout (layout constraints) were enabled. Once I disabled them and set the autosizing appropriately then everything was ok. I guess I should learn about layout constraints...
I know this is very old but I just implemented mouse scroll zooming using the following after spending days trying to figure it out using various solutions posted by others, all of which had fundamental issues. As background I and using a CALayers in a NSView subclass with a large PDF building layout in the background and 100+ draggable CALayer objects overplayed on top of that.
The zooming is instant and smooth and everything scales perfectly with no pixellation that I was expecting from something called 'magnification'. I wasted many days on this.
override func scrollWheel(with event: NSEvent) {
guard event.modifierFlags.contains(.option) else {
super.scrollWheel(with: event)
return
}
let dy = event.deltaY
if dy != 0.0 {
let magnification = self.scrollView.magnification + dy/30
let point = self.scrollView.contentView.convert(event.locationInWindow, from: nil)
self.scrollView.setMagnification(magnification, centeredAt: point)
}
}
LOL, I had exactly the same problem. I lost like two days messing around with autolayout. After I read your update I went in and just added another NSBox to the view and it gets drawn correctly and zooms as well.
Though, does it work for NSImageViews as subviews as well?

Resources