Scroll view scroll indicator visible despite being turned off - ios

I've just added a UIScrollView and when the user scrolls (horizontally) the scroll bar indicator appears at the bottom of the screen (then it disappears when the user stops scrolling).
However in the VC's viewDidLoad I'm setting the SC's showsHorizontalScrollIndicator to NO, also in IB in the Shows Horizonal Scrollers check box is set to off.
So how can I make these scroll indicators permanently never appear?

The horizontal and vertical indicators are type of UIImageView by default. So, if you want to remove it permanently then do this
//Assuming myScrollView is of type UIScrollView
- (void)viewDidLoad
{
[super viewDidLoad];
for(UIView *subview in myScrollView.subviews){
[subview removeFromSuperview];
}
}

Related

UIScrollView is not responded when there are UIView on the same level

I have a container view which contains an UIScrollView and an UIView, that are at the same level with the same frame and bounds, meaning they are subviews of the container view.
But the UIView is on the top of the UIScrollView. So the problem is that the buttons or gestures on the UIView are responded to my touches, while the UIScrollView is not, either scrolling or zooming.
So how can I make the UIScrollView respond to scrolling and zooming and UIView respond to touches at the same time when these two views are on the same level of the same super view?
UPDATE:
What I'm trying to do is I want to have a player control panel view which contains play/pause button, progress button etc., and behind this panel view there is a player render view which is in charge of rendering the video frames.
And I want to make the render view be able to be zoomed and scrolled, while the control panel view stays still.
The sample code is like this:
#implementation MyVC: UIViewController <UIScrollViewDelegate>
- (void)viewDidLoad
{
UIView *view = [UIView new];
UIScrollView *scrollView = [UIScrollView new];
[self.view addSubview:scrollView];
[self.view addSubview:view];
view.frame = scrollView.frame = self.view.frame;
//zooming and scrolling settings code
//now the problem is that scrollview does not respond to my zooming and scrolling
//while the view does.
}
#end
Maybe you can try this:
[view addGestureRecognizer:scrollView.panGestureRecognizer];
Or add any other UIGestureRecognizer in scrollView.gestureRecognizers to view. But it possibly will cause some issues when zooming. I did not check it. Maybe adding your buttons play/pause to the container view on the level same as scrollView is a better way.

UITableview covering button

I tried to make floating button on top of uitableview, I already set uitableview to back and the button is in the front on storyboard but when I run the application the table covering the button. How can I make the button to always on front?
Here is the screenshot:
Try to bring your subviews on top of tableview.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view bringSubviewToFront:yourButton];
}
Set autoresizing mask of your buttons from bottom then check. If buttons are not appearing then add this code to in your viewDidLoad method -
[self.view bringSubViewToFront: btn_Cancel];
[self.view bringSubViewToFront: btn_Delete];

UITableView as ScrollView Between Navigation and Tab Bars

I have a table view laid out between a navigation bar and a tab bar and want to achieve scrolling only for the table view section (so in other words, in my iOS Simulator, I would want the two bars to always be seen, and I should be able to scroll my table view between them).
Having tried out various suggestions from SO posts, afraid am still getting something wrong. Can you advise please how do I fix this issue - I've been struggling with it for the last 1 day!
In the table view controller's viewDidLoad, I use the following code. Earlier, I also tried initializing a scroll view separately but understand that table view is a sub-class of scroll view, so ditched that path...
- (void)viewDidLoad
{
[super viewDidLoad];
// To remove extra separators from the table view to prevent blank rows from showing.
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// ***** Scroll view implementation *****
[[self tableView] setFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height - self.tabBarController.tabBar.frame.size.height)];
[[self tableView] setContentSize:CGSizeMake(self.view.frame.size.width, 2000)];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
self.automaticallyAdjustsScrollViewInsets = YES;
}
In fact, to test this further, I have created a scroll view in a separate tab (in this tabbarcontroller app) where I only have a navigation bar and a tab bar so far (no table view). Its viewDidLoad looks like this - somehow, no luck there as well... the scroll bar starts from the top of the screen (rather than from the bottom of the navigation bar) and goes till the bottom of the screen (rather than till the top of the tab bar). So clearly I'm doing something conceptually wrong here... appreciate if you can help out please!!! The numbers put in here are experimental to test this out but I've ensured that the content size is larger than the scroll view frame...
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 300)];
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, 1500)];
[self.view addSubview:scrollView];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
self.automaticallyAdjustsScrollViewInsets = NO;
[scrollView setScrollEnabled:YES];
}
Finally, when I debug my app in the simulator, what is odd is that for the table view tab, the scroll bar does appear momentarily to start from below the navigation bar. But as soon as I touch the track pad to scroll, it disappears and a more prominent scroll bar appears and starts from the top of screen to the bottom of the screen as I mention initially above!
I think I found the underlying error in my ways. More than an implementation bug, it was me missing out on a very basic issue...
In summary, the iOS Simulator would typically always have higher resolution / number of pixels than the computer screen, and no matter what, the simulator would always outsize the computer screen unless manually resized. So the scroll bar would usually be always present. This SO post helped me understand it.
On the other hand, the UIScrollView was automatically already implemented in my table view, given that UITableView is a subclass of UIScrollView - I didnt have to do anything. I was scrolling the simulator with a 'light' double-touch, which was taking me to the scroll bar due to the issue mentioned above. If I 'hard-clicked' and then scrolled, then voila! The required UIScrollView did work properly as expected! This is probably what misled me to mention these statements in the question...!
Finally, when I debug my app in the simulator, what is odd is that for the table view tab, the scroll bar does appear momentarily to start from below the navigation bar. But as soon as I touch the track pad to scroll, it disappears and a more prominent scroll bar appears and starts from the top of screen to the bottom of the screen as I mention initially above!

UIView inside an UIScrollView did not refresh itself despite call of method "setNeedDisplay"

I've got an UIScrollView with inside, some views loaded from a xib file.
The UIScrollView loads only three Views. The current, the left one and the right one.
For exemple, I have one view at the left and one view at the right of the current View. If I scroll to the right, the UIScrollView will delete the view to the left, scroll to the right to the new current View and load the new view to the right of the new current View.
In addition, I have a button outside the UIScrollView. When I click on it, it changes the background color of the current view displayed on the UIScrollView.
It works well but sometimes, I don't know why, when I click on the button to change the background color of the view is well changed, but the view is not refresh so the user can't see the change of background color.
The UIScrollView:
container = [[UIScrollView alloc] initWithFrame:frame];
[container setBackgroundColor:[UIColor clearColor]];
[container setCanCancelContentTouches:NO];
[container setClipsToBounds:NO];
[container setShowsHorizontalScrollIndicator:NO];
[container setPagingEnabled:YES];
The method call when I click on the button to change the background color of the current view
- (void)menuColor:(MenuPickerViewController *)controller didPickOption:(UIView *)button
{
// Get the object containing the data of the product linked with the view.
MyProduct *product = (MyProduct *)[MyProduct getProduct:[_slider getCurrentContentDisplayed]];
// Get the the superview of the button sender to have an access for the attributes of this button (color selected, ...)
ColorButtonMenu *colorView = (ColorButtonMenu *)[button superview];
// Get the current UIView displayed in the UIScrollView
MyView *myView = (MyView *)[self sliderGetViewWithID:[_slider getCurrentContentDisplayed] FromSlider:_slider];
// I check with debugger, the color is well setted
product.color = colorView.color;
// "border" is a view in my xib that I want change its background color.
IFPrint(#"myView.border backgorund color before: %#\n", myView.border.backgroundColor.description);
[myView.border setBackgroundColor:[Utilities colorFromHexString:colorView.color]];
[myView.border setNeedsDisplay];
IFPrint(#"myView.border backgorund color after: %#\n", myView.border.backgroundColor.description);
IFPrint(#"=== DEBUG ===\n");
IFPrint(#"isMainThread ? : %i\n", [NSThread isMainThread]); // Always return YES
IFPrint(#"myView: %#\n", myView); // Always return the address of a valid pointer
IFPrint(#"myView border: %#\n", myView.border); // Always return the address of a valid pointer
IFPrint(#"=============\n\n");
}
So, as you can see at the end of the method, I tried to call method setNeedsDisplay on the view loaded from a xib and the other view inside "border" but nothings work.
Moreover, my method is always called on the main thread.
Any suppositions ?
Thanks !
Edit:
Obviously, I have tested if the view return by sliderGetViewWithID is the correct view. All the attributes are well set. In my opinion it's truly a refresh problem.
are you sure the view you're trying to set background color for is actually visible? I guess it might be offscreen so you see nothing happening.
You might want to trap that event by finding the intersection between scrollview's bounds and myView's frame. if there's no intersection, that means myView is not actually visible.
so the code is:
BOOL intersects = CGRectIntersectsRect(scrollview.bounds, myView.frame);
if(intersects == NO)
{
NSLog(#"myView is offscreen");
}
Problem solved :
After setting the background color of the view. I remove the view from the UIScrollView and I re add it inside the UIScrollView. It's a bit tricky but it works good !
[myView removeFromSuperView];
[myScrollView addSubview:myView];

Weird interface bug UIScrollView in UITabBarController. Reproducible by others?

I get a weird interface bug with my UIScrollView and I cant figure out how to solve it. I only wrote one line of code (shown below) and it is a blank project's setup easily reproducible!
Setting:
I have a UIScrollView that contains a UISegmentedControl (since the segments of
the control are loaded dynamically, it could exceed the width of the screen and the scrollView is supposed to scroll the segmentedControl horizontally, the height of the scrollview is the same as the UISegmentedControl's).
The ViewController that contains this is embedded in a tabBar (or navigation bar, which also shows the bug). The whole thing is using Auto-Layout.
Bug:
When I scroll the SegmentedControl some degree to the right and then switch the viewController by clicking the other tab on the tabBarController, the content-offset of the segmented control gets weirdly shifted when switching back to the initial viewcontroller. When I try to scroll to the leftmost part of the scrollview it won't let me. When switching the tabs a couple of times, it gets fixed again and I can do this over.
What I did (can you reproduce this?):
Create a blank single-view ios project
Embed the already given viewController in a tabbarcontroller.
Put a scrollView on the upper portion of the view that fits the screen from left to right.
Put a UISegmentedControl on the topleft corner of the scrollview and drag the scrollview to fit the segmented controls height height
Change the Segmented control's width a bit so xcode adds a width-constraint. in the segmented control's width constraint change the width constraint's relation to "greater than or equal"
create an outlet to the segmented control
in viewDidload add this code
[self.segmentedControl insertSegmentWithTitle:#"A really long title so it you have to scroll to see it" atIndex: 0 animated: NO];
Create a blank viewcontroller and add it as a second viewController for the tabbarController.
This is how my storyboard looks like:
Now run the project, scroll the segmented control to it's right end as far as it goes. Switch the tab and switch back and please tell me how your scrollview now behaves - and WHY.
My guess would be it has something to do with Auto Layout maybe? Can't figure out what though.
I tried fixing this by setting the scrollView's contentSize in viewDidAppear or changing the content offset of the scrollView in viewDidAppear or changing frames, combination of those and what not....
Extra question:
Is it no longer neccessary to set the scrollViews contentSize property? Why does it scroll the content automatically?
After googeling I found the answer in another StackOverflow question.
What you need to do is save the scrollview.contentOffset on viewWillDisappear,
set it to CGPointZero on viewDidDisappear and set it back to the saved state on viewDidLayoutSubviews:
-(void) viewWillDisappear: (BOOL) animated {
self.lastContentOffset = self.scrollView.contentOffset;
[super viewWillDisappear: animated];
}
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear: animated];
self.scrollView.contentOffset = CGPointZero;
}
- (void)viewDidLayoutSubviews {
[super viewDidlayoutSubviews];
self.scrollView.contentOffset = self.lastContentOffset;
}

Resources