UIPageViewController - Don't allow to move if no pages - ios

In my app I do not want it to be possible to drag if there is no pages before and/or after.
See the images below.
I do not want it to be able to move if there is no pages before or after the current page. No matter how much you drag, I want it to stay still like the second image, if there is no pages before and/or after.
How it is now when dragging:
How I want it to be when no pages before and/or after when dragging:

Is this what you're looking for?
Disable bounce effect in UIPageViewController:
for (UIView *view in self.pageViewController.view.subviews ) {
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scroll = (UIScrollView *)view;
scroll.bounces = NO;
}
}

Related

iOS temporarily disable Page View Controller swiping

I have a setup where I have a Page View Controller set up to navigate between different views.
In some of these views I will have a custom drawing view where the user can draw with their finger to create a picture.
The problem with this, the user is not able to make a drawing gesture left/right because the page view controller will take over and navigate to a different view.
I was wondering what a good approach would be to temporarily disable the swiping for the page view controller to allow the user to draw.
I was thinking when the user first interacts with the drawing view it would disable the page swiping and create a finished drawing button. When this button is clicked it would reenable the page swiping. Does this seem reasonable, or does anybody know of any better approaches?
Using this you can stop Scrolling
for (UIScrollView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = NO;
}
}
I'd look into this UIGestureRecognizerDelegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
Here you can "kill" the page view controller's gesture recognizer by disabling and re-enabling it:
if (/* otherGestureRecognizer is page view controller's */) {
otherGestureRecognizer.enabled = NO;
otherGestureRecognizer.enabled = YES;
}

Disable scrolling UIPageViewController

I want disable scrolling UIPageViewController until webview is loading in ViewController.
When webview is loaded, then enabled scrolling in PageViewController.
I use:
for (UIScrollView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = NO;
}}
But that disable scrolling forever.
Help me please!
Simple. Inside of your if block, store away a reference to the scrollview for later use. Then, implement UIWebView's delegate method webViewDidFinishLoad: and webView:didFailLoadWithError: and in both of those re-enable scrolling using the reference you captured earlier.
Docs for reference: https://developer.apple.com/library/ios/documentation/Uikit/reference/UIWebViewDelegate_Protocol/index.html

Scroll to top with status bar tap

I've looked through various SO questions on the topic and I have not found a solution. I have a UIViewController with a UITableView and a UICollectionView. I want the UICollectionView to scroll to the top, when the user taps it.
The documents say if you have more than one UiScrollView subclass - you need to set them to no and the UiScrollView you want to scroll to the top, to yes.
So I wrote this bit of code to go through all my views:
for (UIScrollView *view in self.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollsToTop = NO;
}
}
self.collectionView.scrollsToTop = YES;
This way I am sure any subclass of UiScrollView has it's scrollsToTop property set to no.
However tapping on the status bar does not do anything.
Can someone tell me what I am missing here?
Thank you
It seems that you are only iterating through the subviews of your main view. Your UITableView may be nested inside another view. Try doing the following;
//in view did load
[self setScrollToTopFalse:self.view];
self.collectionView.scrollsToTop = YES;
-(void)setScrollToTopFalse:(UIView *)v
{
for (UIView * v1 in [v subviews]) {
if ([[v1 class]isSubclassOfClass:[UIScrollView class]]) {
((UIScrollView *)v1).scrollsToTop = NO;
}
[self setScrollToTopFalse:v1];
}
}

Maps and legal mention

With iOS < 6.0 we were able to re-position the "Google" link over map view (by browsing the subviews of map view). Now with iO6, there's a "legal" link and this is a MKAttributeLabel. A private class that we can't manipulate ...
My problem is that I must add a footer subview to my map and it'll hide the legal link ...
How can I solve this problem without any App Store rejection ?
Can I create another legal button my self and add it where I want in my map view ?
I have no idea what I'm able to do...
There's a few answers recommending you move the legal label in the viewDidAppear of your view controller, however this doesn't work if you then resize your map view (like I am).
The best way is to subclass the MKMapView and override the layoutSubviews method. In my example I just needed to nudge the legal label above a semi-transparent toolbar.
-(void)layoutSubviews
{
[super layoutSubviews];
UILabel *legalLabel;
for(UIView *view in self.subviews)
{
if([view isKindOfClass:[UILabel class]])
{
legalLabel = (UILabel *)view;
break;
}
}
legalLabel.center = CGPointMake(legalLabel.center.x, self.bounds.size.height - 55.0f);
}
Does the footer view have to be inside the map boundary, why not put the map and the footer into the same super view?

How to show UIWebView's scroll indicators

I have a UIWebView with some content and I need to make its scroll indicator visible for a short time (like [UIScrollView flashScrollIndicators]).
Any idea how to do this?
Starting iOS 5.0 onwards, one can now customize the scrolling behavior of UIWebView by accessing the 'scrollview' property to achieve the desired functionality:
[webView.scrollView flashScrollIndicators];
There's no real way of doing this via a published API, however I think that in this case it's OK to guess the UIScrollView subview, so long as you make sure your application doesn't crash if you can't find the UIScrollView:
UIView* scrollView = [webView.subviews objectAtIndex:0];
if ([scrollView isKindOfClass:[UIScrollView class]) {
[((UIScrollView*)scrollView) flashScrollIndicators];
} else {
// If Apple changes the view hierarchy you won't get
// a flash, but that doesn't matter too much
}
EDIT: The above will not work because the first subview of a UIWebView is a UIScroller, not a UIScrollView (my memory might be playing tricks on me). Perhaps try the following?
UIView* uiScroller = [webView.subviews objectAtIndex:0];
if ([uiScroller respondsToSelector:#selector(displayScrollerIndicators)]) {
[((UIScrollView*)uiScroller) performSelector:#selector(displayScrollerIndicators)];
} else {
// If Apple changes the view hierarchy you won't get
// a flash, but that doesn't matter too much
}

Resources