Aligning page control - ios

I have so many images in my page control that indicator dots are out of screen. Is there a way to align page control to left so that the dot related to first page will be visible on screen?
This is how it looks like now:
And this is what I want to achieve
I tried
imagesPageControl.contentMode = .Left
imagesPageControl.contentHorizontalAlignment = .Left
but without success. I have also tried to add some left constrain without right. I'm aware that on the right side page control will be still out of screen.

Scaling is an option if number of pages is constant or at least it has similar value. However, I ended up with manually adjusting the page control frame if it's width is greater than screen bounds.

Related

Do button's touch size change with a CGAffineTransformScale?

My goal was to make a View of buttons and have it grow with screen size so it works on all devices, filling 90% of the width of the screen. I am not using constraints as it is an older program, and turning on constraints would be too big a job right now. I was hoping to "cheat" my way around this. So, I tried this:
I have a smaller View created inside a full screen View (created in interface builder) that is basically a standard "view" item. Inside that smaller View are a bunch of UIButtons that make my "keyboard."
I would like to scale the smaller view (which visually scales the buttons too), and still have the buttons respond properly as they change size. So I have done this:
Setup:
View (buttonView) with UIButtons inside that view. The view and the buttons are attached (in Interface Builder) to IBOutlets and IBActions as necessary. The following code scales the view to match the screen:
_keyboardCard.transform = CGAffineTransformIdentity; // reset to normal
CGFloat keyboardWidth = _keyboardCard.bounds.size.width;
// screenWidth is set earlier and has width bounds value for full screen
CGFloat widthScale = (screenWidth/keyboardWidth)*0.9; // 90% of full screen width
_keyboardCard.transform = CGAffineTransformScale(CGAffineTransformIdentity, widthScale, widthScale);
This actually works visually just fine, and the "keyboardCard" grows in size, as do the buttons inside (visually), just like I expected. It looks good as I change from device to device.
But there are times when some of the buttons stop responding. SOME continue to work just fine, especially near the center, while others just stop. The touch failures start on ALL the edges, and work their way inward as the size grows. It is almost as if there is a "mask" stopping the buttons from working on the edges.
So the question is: Is this a legitimate ways to do this? It does not seem to be documented anywhere. And if not, what does one suggest as a way to make a view with buttons scale up and down and still have the buttons work as expected?
Or perhaps I am just better off making a small, medium, and large View of the "keyboard", and just pick the closest one based on screen size?
Suggestions and comments please. Thank you.

iOS UIScrollView with multiple pages visible

I'm having a little issue with scrollview pagination.
My intention is to have 3 pages visible on screen and when I scroll right only on page is scrolled, following the example below, scrolling right will display page 2, 3 and 4 on screen:
However I don't know how to display mutiple pages at the same time, at the moment I have it like this:
Obviously like this is not what I want.
To achieve the desired functionality I tried making the scrollview's frame the size of the page I want (1/3 of the screen width) and setting the clipToBound to NO so the other pages are visible. This indeed shows 3 pages in the screen; however since the scrollview frame is only 1/3 of the screen I can only swipe in that area, I would like the swipe area to be the whole screen width.
You're on the right path. Now you can try manipulating UIPanGestureRecognizer of your scrollView, say, re-attaching it to scrollView's superview.
Alternatively, take a look at iCarousel, it can be perfectly customized to suit your needs.
My solution in the end was the following:
I took my initial approach.
I disabled the scrollview's scrollEnabled property.
Added swipe gesture recognisers to the scrollview.
When the gesture is made I modify the scrollview's contentOffset to move 320/3 pixels to the right or left.

UIWebView contentInset without extra height at bottom

I'm creating a view controller that uses a web view which slides behind the navigation bar and status bar. To do this, I'm setting the webView.scrollView.contentInset property to have a top inset of 64.
However, this doesn't shrink the amount of area the web view wants to take up, so if a page is less than a screenful, it has 64 px of white space at the bottom to scroll through. The web views are in a vertical UIPageViewController, so this disrupts paging. Is there some way to get rid of this extra space?
Have you tried something like adjusting the webview's scrollview content insets? Example:
webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0,64, 0)
It sounds like what you need is to adjust the webView.scrollView.contentSize and adjust the height by 64. You may need to provide more information about how it slides behind the nav bar and status bar to help me answer this. I would take a look at this section of the Scroll View Programming Guide:
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html
Change the clipsToBounds.
webView.clipsToBounds = NO;
This will make its content visible outside its frame, so set its frame like normal, right under the navigation bar. The navigation bar will be translucent and you will see its content under it.
Don't forget to disable Autolayout for the web view!
I've sort of made an end-run around this problem by disabling scrolling on short pages. Basically, I use -stringByEvaluatingJavaScriptFromString: to run some JavaScript inside the page that walks down from document.body and computes the position of the bottom of the bottommost element. (document.body itself is always at least as large as the viewport, so I can't look at its size.) Then, back in Objective-C-land, I compare that to the height of the web view (less the inset), and if it's less, I disable scrolling. This is not a perfect solution, but it covers the worst symptoms.
If someone can come up with a better solution than this, I'd love to hear about it! Either way, I can't award the bounty to myself, so someone will be getting it.

Is there a way to make something truly free scrolling div (any direction) on iOs webview

I want a div that can be dragged any direction and is about 4x width and 4x height of the screen.
I set the body height and width, and you can scroll it diagonally some of the time, but other times when you go to scroll it will go only straight vertically or straight horizontally. It seems to be when you start scrolling straight up, it sticks that way. Is this normal for scrolling in an oversized webview div, or is there something else that might explain this?
This is on an iPad, with a body set to width:4000px and height:3000px.
The iPhone's tendency to scroll exactly horizontally or exactly vertically is intentional, and it's usually a useful feature: if you're reading a tall column of text that could scroll horizontally, it's nice to be able to scroll down without worrying about accidentally moving the view from side to side as you go. As far as I'm aware there's no way to turn this behavior off.
there is a property name directionalLockEnabled that get a bool
in scrollView class.
this will do the trick:
theWebView.scrollView.directionalLockEnabled = NO;

UIScrollView with pagination + showing part of the previous/following pages

I'm trying to create a kind of a "game mode" menu similar to the one used by the "Cut the Rope" game to select the level pack:
What I want in particular is to achieve the same effect of showing the "current item" (in this case, the "2. Fabric Box" item) plus a bit of the previous and following items (to make sure the user is aware that there are more modes available by scrolling), with pagination enabled (to make the scroll view automatically "center" on these items).
This seems like a natural job for a UIScrollView with pagination enabled, however from the documentation it seems the pagination occurs on multiples of the view bounds.
So: if pagination occurs on multiples of the view bounds, is there any way to achieve this effect with a UIScrollView?
The fact that we see the full width of the screen would suggest that the UIScrollView frame's width would be 320px in this case, but each individual item would need to be smaller than that in order to show that little bit of the previous and next items, thus messing up the pagination...
For your reference, you can see a sample implementation of a page control from here.
https://developer.apple.com/library/content/samplecode/PageControl/Introduction/Intro.html
For the implementation you want,
to your surprise, the scrollview's width is actually smaller than 320 (or 480). The magic property to set is:
scrollView.clipsToBounds = NO
The only problem with this implementation is that the scrollview get no touch events if the touch is outside the bounds of the scrollView. This can be fix by passing its parent hitTest event to scrollView.
Just to link to to a better explanation:
UIScrollView horizontal paging like Mobile Safari tabs
Slightly different from what I recommend but does the same thing.
Edit:
I have a small project called LXPagingViews that does the above, hopefully in an out of the box manner (Do drop me a pull request or feedback in issue): https://github.com/lxcid/LXPagingViews

Resources