UIPanGestureRecognizer + UIViewController - ios

I am adding a UIPanGestureRecognizer to a partially hidden UIViewController (it is there to pull it back on screen). All is working fine except on the odd occasion when the UIViewController has a scrollable subView (i.e. UIScrollView, UITableView). I can't set useInteractionEnabled = NO because this disables my gesture... Any suggested workarounds?
EDIT:
I have this work around and it is achieving what I want...
for(UIView *subView in sender.view.subviews) {
[subView setUserInteractionEnabled:NO];
}
But I feel there should be a better solution?

The best I have come up with is
for(UIView *subView in sender.view.subviews) {
[subView setUserInteractionEnabled:NO];
}

Related

UISearchBar on UITableView with scope bar resizes itself over other UI items

Ok, so I've got a UITableView below a UISearchBar. Above that is just some UILables and UIButtons and then the UINavigationBar.
The UISearchBar has the scope bar enabled. Whenever I tap on the search bar I get the following odd behaviour (I've got the on screen keyboard disabled but the focus is in the UISearchBar text field):
Where as normally it looks like this:
It's really frustrating and I can't work out why it's happening. Has anybody experienced anything similar and found a solution?
Thanks!
It's a bodge, but it's the best I could come up with. I just put the following in viewWillAppear and then manually created a background image of 44px high and put it behind the UISearchBar on the storyboard.
-(void)viewWillAppear:(BOOL)animated
{
[self.searchBar sizeToFit];
for (UIView *subview in self.view.subviews) {
for(UIView *subView2 in subview.subviews){
for(UIView *subView3 in subView2.subviews){
if ([[[subView3 class] description] isEqualToString:#"UISearchBarBackground"]) {
[subView3 removeFromSuperview];
break;
}
}
}
}
}

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];
}
}

Looping Through UIScrollView and Setting UImageView

I am trying to implement lazy loading of images in a UIScrollView but I am having some problems trying to set the images.
The user scrolls and I use the following to detect what the next view tag should be. I then want to be able to loop through the corresponding UIView and set its UIImageView image.
The following is not working and I was hoping someone could help me to correct it.
for (UIView *subview in self._scrolViewForEffects.subviews){
for (UIImageView *view in subview.subviews){
if([view isKindOfClass:[UIImageView class]]){
if(view.tag == currentPage){
if(view.image == nil){
[view setImage:[UIImage imageNamed:#"Theme1.png"]];
}
}
}
}
}
It is not enough information to say what problem you can have but I suggest you to execute in debugger window a command
po [self._scrolViewForEffects recursiveDescription]
to check your view hierarchy at runtime.
Turns out that it wasn't to do with the code above. It turns out that I wasn't setting the tag on the UIImageView when I was creating it.
Thanks for the help!

iOS XCode Add the scrollbar indicator program programmatically

I'm currently coding a iOS apps that contains a scrollview in the mainview. When the user want to reset the scrollview I'm running this method:
-(void)clearFlightTimer{
// Removing object (button, label and image) from subview
// *** KNOWN BUG WHEN REMOVING UIImageView OBJECT IT'S ALSO REMOVING THE SCROLLBAR IMAGE ***
for(UIView *subview in [self.flightViewScrollView subviews]) {
if([subview isKindOfClass:[UIButton class]] || [subview isKindOfClass:[UILabel class]] || [subview isKindOfClass:[UIImageView class]]) {
[subview removeFromSuperview];
} else {
// Do nothing - not a UIButton or subclass instance
}
}
// Reloading the View
[self viewDidLoad];
[self viewWillAppear:(YES)];
}
The issue is that the scrollbar seem to be part of UIImageView class and this method remove it. How could I keep the scrollbar image when removing all object from this subview? Is there a way to code the scrollbar indicator back programmatically?
Thanks!
Hope that I'm clear!
The simplest and most fool proof way is probably to add an intermediate subview of the scroll view that contains your actual content. This new container view's subviews can be iterated over and removed as you need. Alternatively, if you know the scroll view is in an empty state, you might be able to iterate over subviews of the scrollview and store all image views that exist when empty - those views will be the ones you shouldn't mess with.

Remove line UISearchBar with UISearchDisplayController when remove the background color

I have added with help of interface builder a UISearchBar With UISearchDisplayController in my UITableView. I know how to set the background color of UISearchBar, I do it this way:
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
but you can see, there is a line, that I can't understand , and how to remove it, that scroll with the searchbar:
if I insert with interface builder only a UISearchbar without UISearchDisplayController there isn't that line, how I can remove that line?
Use this instead:
for (UIView *subview in self.searchDisplayController.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
When we use UISearchDisplayController, the searchBar gets associated with the searchBar property of UISearchDisplayController and can be accessed using self.searchDisplayController.searchBar
I am using 1px image with 0% opacity (image)
self.searchDisplayController.searchBar.backgroundImage=[UIImage imageNamed:#"image"] ;
and its work perfect as what you want.

Resources