iOS6 ScrollBarShouldScrollToTop not firing/ ScrollView Delegate issue - uiscrollview

I am adding a dummy ScrollView to my app to detect a user click on the status bar, to performa an event in my program.. I am creating it in the ViewDidLoad:
//Dummy Scroll is for the tap on status bar to work
UIScrollView *dummyScrollView = [[UIScrollView alloc] init];
dummyScrollView.delegate = self;
[[self view ] addSubview:dummyScrollView];
[[self view] sendSubviewToBack:dummyScrollView];
I then implement :
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
NSLog(#"scrollViewShouldScrollToTop");
.
.
}
Under all previous versions of IOS this has worked beautifully and flawlessly, yet under iOS 6 the scrollViewShouldScrollToTop never gets called. Is this a bug?? The API says this should still be available as part of the delegate in iOS6, yet under iOS6 on both device and simulator it never executes... Anyone have any idea what is going on?
Still no other TableView or ScrollView, but there is a MAPVIEW?? But the MapView doesn't have a shouldScrollToTop that I can find to set to NO.. so I am still beyond confused why this stopped working under iOS 6...

Is there any chance that the UIScrollView you're creating isn't somehow the only UIScrollView in your view hierarchy? It looks like in iOS6, if you have more than a single UIScrollView in your view hierarchy, only one should have scrollsToTop = YES. This is the one that'll have its scrollViewShouldScrollToTop method called.
My problem was similar in that I had a very basic UITableView that would no longer autoscroll to the top when the status bar was tapped. I finally remembered that one of the cells in my tableView uses a UIWebView, and that the cell's webView.scrollView was (correctly, now in iOS6) hijacking the call to scrollViewShouldScrollToTop that, before iOS6, was being made on my tableView.
After setting the tableViewCell's "scrollsToTop = NO", the status bar autoscroll once again worked as it did before. Here's more-or-less how the code looks:
myCustomCellWithAWebView.webView.scrollView.scrollsToTop = NO;
Hope this helps!

On iOS 6, only tap the part above scrollview of status bar can fire scrollsToTop event.
And, that scrollView can't be hidden or 0 alpha.
But it can be covered. or clear background color.
So on iOS 6, you need
dummyScrollView.frame = self.view.bounds;
dummyScrollView.backgroundColor = [UIColor clearColor];

Related

ViewController canBecomeFirstResponder iOS 8

I have a VC that has an inputAccessoryView that is used to display a textfield (much like the messages app). When I push this view onto the navigation stack everything works fine and by that I mean that the tableview adjusts its insets to make sure nothing scrolls underneath that accessory view. However, if from that view I push on another instance of the same view controller class the insets will not be adjusted and the scrolling of the table will be behind the accessory view.
This issue is seen in iOS 8 only. The other interesting thing about this is that if you then click in the accessory view to open the keyboard the insets are adjusted properly for the keyboard being visible and again when it's hidden.
Also if you don't click the text field to fix the issue and hit back the previous VC is broken as well.
I'm fairly certain based on the information above that this is an iOS 8 bug. I'm hoping someone has seen this and come up with semi reasonable fix.
Nasty solution but a solution nonetheless:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.inputAccessoryView.inputAccessoryTextField becomeFirstResponder];
[self.inputAccessoryView.inputAccessoryTextField resignFirstResponder];
});
}
This allows the view to redraw the insets

UIScrollView with UIButtons - Scroll View won't scroll when touch began on button

I just updated to xCode 6 and iOS 8 and I noticed something very weird with my app. In my app I have a scrollview with several buttons within it, aligned horizontally. I set it up to create my own custom scrollable tab bar controller. Before the update to iOS 8 and xCode 6 everything was working perfect, but now I realized that when I try to scroll the scrollview left or right, and my initial touch was within one of the buttons in the scroll view, then no scrolling happens. However if I touch in-between the buttons then scrolling works as expected. I think it's some issue where the button is registering the touch and it is as if the scrollview never got touched. But this was 100% working before perfectly so i do not what is going on!!
I ended up creating a subclass of UIScrollView and set it's cancelContentTouches value to TRUE and my problem was solved
Subclassing UIScrollView and adding code below into .m file, did solve my scrolling freeze problem under iOS 8.
Code:
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
UITouch *touch = [touches anyObject];
if(touch.phase == UITouchPhaseMoved)
{
return NO;
}
else
{
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}
}
This solution was found in pasta12's answer https://stackoverflow.com/a/25900859/3433059
No need to subclass ScrollView
Just use this :
yourScrollView.panGestureRecognizer.delaysTouchesBegan =yourScrollView.delaysContentTouches;

Adding a UIDatePicker as an inputView to a textField in iOS 8

I have an UIDatePicker in my storyboard view connected to an IBOutlet in the header file.
In the implementation file I set some properties to the picker and then assign it to my textFields:
[self.txtEndDate setInputView:self.picker];
This was working fine in iOS 7, but with iOS 8 it's giving me the following error:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7c2d8800> should have parent view controller:<InserimentoDurata: 0x7aec2b10> but requested parent is:<UIInputWindowController: 0x7b92b400>'
Any idea on how to fix this?
After receiving an email from Apple's Developer Technical Support, it seems that to add a UIDatePicker (or any custom keyboard for what I've understood) to a viewController, you don't have to add it to its view anymore, but you add it to its title bar and then connect it to the IBOutlet.
It's working for me, even if it doesn't work in the iPhone 5 simulator (all the others are ok) and I was going nuts.
I hope this could be of help for other people with the same problem.
The solution is to build your UIPickerView in code (remove it from the Storyboard), assign it to the textfield's inputView, and retrieve it from there anytime you need it (instead of keeping a reference to it). Basically, this means:
UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 300, 320, 168)];
[picker setDataSource: self];
[picker setDelegate: self];
picker.showsSelectionIndicator = YES;
self.textField.inputView = picker;
If you later need it, use:
UIPickerView* pickerView = (UIPickerView*) self.datePartySizeTextField.inputView;
[pickerView selectRow:1 inComponent:0 animated:NO];
UIDatePicker should not be child of any super view
Problem:
You have to ensure that the view you will assign to inputView or inputAccessoryView don't belong to any parent view. Maybe when you create these views from xib inside a ViewController, by default they are subviews of a superview.
Solution Tips:
Using method removeFromSuperview for the view you will assign to inputView or inputAccessoryView
see detail in this link
Error when adding input view to textfield iOS 8

UISwitch doesn't work on Google Maps SDK for iOS?

I'm trying to create a UISwitch laid on mapView_ of Google Maps for my iOS app, but it seems not to work.
In details, I first followed instruction from google, created mapView_, then made it my viewcontroller's view:
self.view = mapView_;
Then, I created an UISwitch programmatically and added it as a subview:
mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 360, 0, 0)];
[mySwitch setBackgroundColor:[UIColor clearColor]];
[mySwitch addTarget:self
action:#selector(changeSwitch:)
forControlEvents:UIControlEventTouchDown];
[mapView_ addSubview:mySwitch];
But when I touched the switch both in simulator and device, it didn't change its state from ON->OFF or OFF->ON. I even tried different UIControlEvent, such as UIControlEventValueChanged but it didn't work. To make sure that the code should work, I tried on a normal view of a normal test viewcontroller (that means, not using google maps), it worked fine!
Does anyone have any comment about this issue?
Thanks heaps!
You can work around this issue by adding both the UISwitch and the GMSMapView to a single UIView parent, instead of adding the UISwitch as a child of a GMSMapView. Yes, this means you need to position both the GMSMapView and the UISwitch.

How to customize / style a UIPopoverController

I'm working on an iPad application and I'm using UIPopoverControllers. I'm at the part where the app needs to be branded and styled and i'm wondering how to change the color / tint of the UIPopoverController? Standard is dark blue but it needs to be another color..
is this possible?
Greets, Thomas
This is possible starting in iOS 5.0 by subclassing the abstract class UIPopoverBackgroundView and assigning your subclass to the popoverBackgroundViewClass property on your UIPopoverController instance. Unfortunately there is no tintColor property as the popover needs to use images for it's arrow and border in order to achieve smooth animations during dynamic resizing. You can learn more about how to customize the appearance of a UIPopoverController in the UIPopoverBackgroundView Class Reference
It's impossible for now.
It's what I call the "Box in a Box" model. You get control of the box inside of the box (the UIViewController inside of the UIPopoverController), but you have very limited control over the actual popover itself. Outside of the arrow direction and the size, you can't change much else. There are also options for a modal effect popover, which dims everything else when it shows up, but I haven't tried to get it working.
I'm sure you've noticed there is no UIPopover class by now.
The answer you want to hear:
If you really want to style one that bad, just write your own. It's really not that hard.
The link you want to click:
Cocoacontrols is an index of iOS and OSX components available on GitHub, they have some popover stuff.
iOS 7 introduces backgroundColor property of UIPopoverController which affects/includes the navigation background color as well as arrows of popover.
#property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);
Usage example:
if ([self.popoverVC respondsToSelector:#selector(setBackgroundColor:)]) { // Check to avoid app crash prior to iOS 7
self.popoverVC.backgroundColor = [UIColor greenColor]; // [UIColor colorWithPatternImage:#"..."] doesn't reflect the color on simulator but on device it works!
}
Note - As of now (iOS 7.0.3), in some cases (like set color using colorWithPatternImage:), the simulator (and even some devices) doesn't honor the color.
Throwing my hat in here;
I've leveraged UIPopoverBackgroundViews in iOS 5+ to add a simple tintColor property onto UIPopoverControllers.
PCPopoverController: https://github.com/pcperini/PCPopoverController
I try to trick it by customizing the view controller inside the popover and then hiding the popover border using this code:
UIView * border = [[insideViewController.view.superview.superview.superview subviews] objectAtIndex:0];
border.hidden = YES;
The app is actually still in development so I'm hoping other people will comment on this solution.
check out these latest projects leveraging UIPopoverBackgroundView
https://github.com/CRedit360/C360PopoverBackgroundView
https://github.com/GiK/GIKPopoverBackgroundView
from ios 5 onward it is can be done, here is a library
https://github.com/ddebin/DDPopoverBackgroundView
just look at the documentation , and it is quite easy
good luck
You can use Elegant Popover cocoapod for just that. You can customise shape and colour of the arrow and the popover itself. Also, you can add colourful borders to the popover.
I know this is a lousy constructed answer, but I've just been playing with the UIPopoverController's views. They do exist.
The only way to access them is from your view that is sitting in the UIPopovercontroller.
I have a navigation controller so I follow this hierarchy
UIView *test = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
UIView *test2 = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
test.backgroundColor = [UIColor greenColor];
test2.backgroundColor = [UIColor greenColor];
This isn't exactly the end goal, but it is really close.
you'll find that the_view_in_the_popover.superview.superview (maybe just one superview if you are not reaching out from a navigation controller view) is a UIPopoverView. If you cast it as a UIView and treat it as a UIView you're not really breaking any rules. I guess that is really up to apple though.
Remove UIPopoverController border:
NSArray* subviews = ((UIView*)[popupController.contentViewController.view.superview.superview.superview.subviews objectAtIndex:0]).subviews;
for(UIView *subview in subviews){
[subview removeFromSuperview];
}

Resources