is it possible to move the UIScrollView indicator from the right side to the left? - ios

I realize I can rotate the cells and move the indicator by displaying the scroll view "upside down" but that requires a lot of other rotations, and manipulating of information to make the Table scroll properly.
Thanks for the time

Actually, it is possible by changing the scrollIndicatorInsets property to restrict the indicator to a small area on the left side:
tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,0,tableView.bounds.size.width-10);

I like Jeremy Jay's solution (though I haven't tested it), but just to thoroughly explore the idea... here's another that might be worth trying (though it's also untested):
Use two scroll views.
One scroll view (we'll call this the "real" one) contains your content but has its indicators hidden. Another scroll view contains no content but has its contentSize set to match that of the "real" scroll view's. When the "real" scroll view's contentOffset changes (as observed via delegate messages), change the "fake" scroll view's offset to match. (Check out the scroll views session from WWDC 2012 for more on the idea of using a scroll view without a content view.)
In theory (again, I haven't tested this), you now have a scroll indicator view that's separate from your original scroll view, and you can place it wherever you like in relation to the original. Layer it on top of the original and move/size it so it occupies a narrow sliver on the left, and you have a left-side scroll indicator. (Alternately, layer it atop the original and flip it horizontally with an affine transform.) Put it somewhere else entirely to take your UI on a trip to crazy town. (Or don't.) Make sure you make it ignore touches if it's layered on top, though.

A quick way to achieve this (if you're not using row actions) without having to calculate insets or messing with additional table views, would be to transform the table view across the Y-axis (flip) and then transform the cells back when you get them.
tableView.transform = CGAffineTransformMakeScale(1, -1);
and then
cell.transform = CGAffineTransformMakeScale(1, -1);

Related

How to center content inside collection view in exact center of shown ring view while scrolling horizontally (iOS)?

I want to set center the content inside a UICollectionView according to ring image in the center of the whole screen. Please check the image below. Any Suggestions?
The function you need is this one... https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/1618007-collectionview
This function is called by the collection view when the user finishes scrolling. It provides the content offset of where the collection view will stop scrolling. (The proposed content offset).
You then need to take that offset and work out the nearest offset to place your cell in the middle of the screen.
Something like, find the item that will be closest to the middle. Work out how far away from the middle it is so you know how much to shift it by. Then apply that shift to the proposed content offset.
This will allow your collection view to decelerate naturally but always stop at the point that you want it to stop.

How to correctly animate change of size of a paged UICollectionView

I have an iPad app similar to the iPad Keynote with a narrow overview on the left and a paged UICollectionView of my "slides" on the right. The collection view is using the default FlowLayout. Some of these slides are standard PDFs and some are embedded UIViewControllers that have been scaled (with a CGAffineTransform) and embedded in the cell. I'd like to smoothly animate the overview sidebar offscreen and zoom the current page cell to fullscreen. The collection view should allow paged swiping at whatever size. I'm using storyboards and autolayout.
I think I need to simultaneously animate about three things:
The collection view constraints (to the sidebar) to enlarge/shrink it
The flow layout's sizeForItemAt: value
The CGAffineTransform on the embedded view controller.
I have some pieces working (a single embedded View Controller "slide" that scales correctly) but cannot get the collectionView/cell resize dance to work correctly. The cell resize animation is jerky, or ends up with the wrong offset, or works for the leftmost cell but not for other cells.
I've tried most of the suggestions in the answers to this question but with no convincing success. I can't believe it's impossible but at this point I'm considering the smoke and mirrors approach of animating a static slide and hiding it after the animation completes. The attached video - ignoring the glitches - illustrates the kind of effect I'm after:
It's worth noting, on close inspection, that Keynote cheats somewhat when it comes to swiping between slides in edit mode, and manually manages the next slide sliding onscreen, so probably doesn't use a UICollectionView.
Has anyone done anything similar, or have any suggestions for things to try?
I managed to solve this. There's a proof-of-concept GitHub repo here.
There are a few moving parts:
There are two pieces of UIView scaling code. I suspect these could be combined with suitable delegate references as the nested view controllers are embedded. The first piece scales (statically) correctly when the Collection View cell is created. The second is an animated scale/translate when the sidebar size is changed.
I added a FlowLayout subclass to remove flicker as the collection's layout is invalidated during scaling.
The sidebar-related transform in the top-level VC uses most of the tricks in the book - invalidateLayout(), performBatchUpdates(...), layoutIfNeeded() etc. as well as animating the contentOffset to the correct value. Some manual tracking of the correct page/slide is required.
There's still a slight flicker occasionally at the start of resizing. This may not be an issue with my particular colour-scheme which will be black on dark gray. Bonus points if anyone can suggest how to track this down or alleviate it.

Custom Collection View Layout like Chanel app

I'm trying to do a custom layout like the Chanel app you can find the app in the Appstore.
https://itunes.apple.com/us/app/chanel-fashion/id409934435?mt=8
I know they are using an UICollectionView, but no clue how to start.
The interaction feels like a tableview mixed with a paginated scroll. When you scroll the elements grow, and the first element position itself at the top.
Start with dragging & positioning just one UIView. See UIGestureRecognizer docs and look for existing examples of movable views. You'll need an UIPanGestureRecognizer to move the view.
Resize the view depending on its Y position.
Create & position an image inside that view depending on the view size using a couple autolayout constraints.
Note that Chanel app has different constants for these constraints. With a minimum view height, one image's top is 80% height, for another image it's 90% height. Make sure you can manipulate constraints from code (I think it's a good idea to create everything from code there, XIBs are not very flexible).
Make the view "anchoring" to certain points (e.g. top = -75%, 0%, 75%, 90% from what I see in the Chanel app) when you stop moving it. Just find the nearest one and animate the view to it.
Once you did it with 1 view, move all your work to an NSView subclass (if it's not yet there) and create a collection of these views.
You can create UICollectionView, but I'd rather do it with a simple NSArray: I actually don't see a reason to use UICollectionView here; it's a very simple structure. Anyway, you write your own gesture recognizer (don't you? I can't see another way) - so what's the point to use UICollectionView? If you want to expand the app functionality some day, UICollectionView will unlikely help you with that. Well, it's my hypothetical approach, you can find another one while working on that.
Position other views while you're moving an "active" view. Do it by hand, without any UIScrollViews.
Write a function that reflects the Y position of the "neighbor" views while you moving one. It should "slow down" to the bottom of screen.

How can I dynamically add/remove a button in a UIView and reposition the buttons below it and vertically resize the view?

I have a UIView, defined in a nib, and I need to be able to show/hide a middle button in that view. When I show the button, I need to reposition the two bottom buttons below it, as well as make the view taller to make room for everything. When I hide the middle button, I need to move the two bottom buttons up and vertically resize the view to make it less tall. I do NOT need to animate any of this since it the changes will never occur while the view is visible to the user.
I'm new to iOS and I'm used to using Autolayout, but I can't use Autolayout in this case to handle this automatically, so my current approach is to hardcode the frame position and dimensions for the two bottom buttons for each of the two different situations. I'm also hardcoding the two different frame sizes for the view itself. In viewDidLoad, I determine if I need to show/hide the middle button and set the frames for the view and bottom buttons appropriately. This works, but if feels hacky. Is there a better way I should be doing this?
Thanks in advance for your wisdom!
You don't need to hardcode your frame sizes in viewDidLoad. The only thing you should take care of is determining that whether you need to show you middle button or not. Within the implementation file where you are allocating your UIButtons, check if the middle button has to be shown, if Yes allocate it, if not then don't. The frames of two buttons and the view should contain a factor which can set/size them accordingly.
You'd basically be managing the Auto-layout programmatically. And if you're not even allowed to that then whatever else you'd end up doing would pretty much be a hack.

What is the best way to animate the size of sub view in a UIScrollView?

I've got a scrollview that allows the user to scroll between different pages and then tap on one to have it expand so that they can read the page in full, a little like how one changes tabs in Safari on the iPhone. Changing the frame size of each sub view is a bit of a pain when rotating as the scroll position is getting lost as the content size of the sub view has to change too. I was wondering if there was a more effective way of
resizing the views for entering 'viewing' mode or rotating the device.
The solution to your first problem is when you want to expand the view, pull it out of the scrollView then add it to self.view.subviews with an appropriate frame, then animate the frame to fill the screen. When done with it do the reverse, shrink it, then when its back to the appropriate size stick it back in the scrollView.
If for some reason this does not work - the scrollview is showing other stuff that gets moved when you remove the view, then instead of just removing your view from it, create a simple UIView of the same size as the view you will expand, and essentially replace the view you pull out with the "placeholder" view.

Resources