I have a UIPageControl which is updated based on a UIScrollView (numberOfPages and currentPage).
It has black and gray colors for current page and other pages dots, respectively.
When loading the app for the first time, only the current page dot shows up, not the gray ones. After scrolling the view, the gray dots appear and everything is fine.
What could be causing this?
Update:
So, I set the UIPageControl to have 3 pages
self.pageControl.numberOfPages = 3
and I set the current page
self.pageControl.currentPage = 0
The page control should present like o x x (o - selected, x - unselected), but it actually shows only the current page: o
Then I did this:
for i in 0..<(self.pageControl.numberOfPages) {
self.pageControl.currentPage = i
}
self.pageControl.currentPage = 0
which solves the problem. Obvisously, it's an hack.
So I wonder if this a bug with the page control or something that I'm doing wrong..
Please provide us more information. As per your short description i can give you below suggestions.
1. Check page control frame.
2. Change your de-select state page dot color. It might be matching with your first page’s background color so that’s why it’s not showing.
The easy solution I found is as below.
// lets set current page from 0 to N number of items
for i in 0..<adsArray.count {
pageControl.currentPage = i
}
// set current page back to 0 as we need
pageControl.currentPage = 0
Related
I'm trying to add an UIPageControl and UICollectionView. My collection is enable paging, and now I want my page control numberOfPages is the collection view number of page.
I try to set it like this:
self.pageControl.numberOfPages = self.gridMenuCollection.frame.size.width / self.gridMenuCollection.contentSize.width;
but it's not work. If using my data array for numberOfPage it return alot of dots and I don't want to do it.
Can anyone help?
You are doing the devision the other way around.
Should be:
self.pageControl.numberOfPages = self.gridMenuCollection.contentSize.width / self.gridMenuCollection.frame.size.width;
And also use ceiling to show the correct amount of dots. like this
e.g.
content width is 1200
frame width is 500
content / frame = 2.4
ceil(content / frame) = 3
And you want to show 3 dots, because the elements will fit only to 3.
I have a horizontal UIScrollView that has a width of 960.
The UIScrollView contains 3 UIView's, each one set to a background color.
The first one is pink, the second blue, and the third is green.
What I need to do is change the alpha of the colors(views) based on the user scrolling.
So if the user is on the first screen (pink) and starts to scroll to the second page (blue), then the pink should start to fade and the blue will become more visible, and once the user fully swipes to that 2nd page it would be all blue.
Here is how I do this when using only one UIView:
func scrollViewDidScroll(scrollView: UIScrollView) {
// Offset Percentage
var percentageHorizontalOffset = scrollView.contentOffset.x / 320;
// Reduce alpha
pinkView.alpha = percentageHorizontalOffset
}
This is easy because the percentage goes from 0.0 to 1.0
However, I need to modify the code to support 3 screens. I tried this earlier by replacing 320 with 960 in the method above but this causes a couple problems.
The first is that you are no longer getting a percentage in the range of 0.0 to 1.0, once you scroll on the second page it will be a range of 1.0 to 2.0 which won't help me properly modify the alpha.
The second is that the alpha change doesn't feel very smooth, especially when the UIScrollView is swiped quickly. I setup a mess of if statements earlier trying to get this to work but nothing worked.
How can I properly fade the alpha of all 3 UIView's based on the contentOffset.x when my UIScrollView's content size is bigger than just one screen?
Simplest way would be to treat the 3 colored views as an array.
// Put all your views in an array
#property NSArray *coloredViews;
// Later where you set things up, allocate the array.
coloredViews=#[pinkView,blueView,greenView];
Then use the following algorithm to set the alpha.
This assumes only 2 of N views on screen at a time. One on left and one on the right.
The alpha of the left is based on the amount of it off screen.
The alpha of the right is based on the amount of it on screen.
So as left goes off it goes to 0 causing right to go to 1 and vice versa.
This makes your scroll method:
func scrollViewDidScroll(scrollView: UIScrollView) {
// Work out which view is showing on the left. 0 to N-1
// Based on each being 320 wide.
CGFloat offset=scrollView.contentOffset.x;
NSUInteger leftHandSideViewIndex=(NSUInteger)offset.x/320;
// Left hand side alpha is 1 minus percentage (as a fraction) off screen
self.coloredViews[leftHandSide].alpha =
1.0 - (offset - (320.0 * leftHandSideViewIndex))/320.0;
// Right hand side alpha is 1 - percentage (as a fraction) on screen
// Only do this if there is a right hand side.
if (leftHandSideViewIndex < self.coloredViews.count-1){
self.coloredViews[leftHandSide+1].alpha =
1.0 - ((320.0 * leftHandSizeViewIndex+1)-offset)/320.0;
}
}
Give it a try. Might not be 100% right, but hopefully gives you the idea.You probably want to set a width variable rather than using 320.0.
I think this is rather easy achieved, but I couldn't find out how to- and couldn't find much documentary about it.
I hate those 'scroll to top' buttons that appear after you already scrolled just 300px. Like I'm that lazy to scroll to top on myself. Therefor I would like to have a scroll to top button that only appears when you reached the bottom of the page (minus 100vh (100% viewport height).
Let's take in account the button is called .scrollTopButton and it's CSS is opacity: 0 and it's position: fixed on default.
How would I make the button appear when you reached the bottom of the page, minus 100vh and scroll along?
I was thinking of comparing the body height minus 100vh with (window).scrollTop().
var vH = $(window).height(),
bodyMinus100vh = ($('body').height() - vH);
if (bodyMinus100VH < $(window).scrollTop) {
$('.scrollTopButton').toggle();
};
Fixed it myself. Quite easy, honestly.
$(window).scroll(function () {
var vH = $(window).height(),
bodyHeight = ($(document).height() - (vH * 2)),
// When you open a page, you already see the website as big
// as your own screen (viewport). Therefor you need to reduce
// the page by two times the viewport
scrolledPX = $(window).scrollTop();
if (scrolledPX > bodyHeight) {
$('.scrollTopButton').css('opacity', '1');
} else {
$('.scrollTopButton').css('opacity', '0')
};
});
I'm using FPPopover to present a pop over view for my iPhone app. I'm having an issue, however, where when I present it, it will only allow me to present it so low or it will jump to the top. And this is well before it gets cut off anyway.
For example:
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
Works fine, but if I put it a 255 instead of 235 (as it's a good 40px from the bottom) it jumps back up to the top.
Does anyone have any experience with this or how I could fix it?
Also, bonus points if you can explain why the content for the popover always starts like 50px from the top, when I want it to start up higher. How can I change this also?
More code from the creation:
- (void)speedOptionsTapped:(UIBarButtonItem *)sender {
// Set the delegate in the controller that acts as the popover's view to be self so that the controls on the popover can manipulate the WPM and number of words shown
self.speedOptionsController.delegate = self;
self.speedOptionsPopover.arrowDirection = FPPopoverNoArrow;
self.speedOptionsPopover.border = NO;
self.speedOptionsPopover.contentSize = CGSizeMake(320, 190);
[self.speedOptionsPopover presentPopoverFromPoint:CGPointMake(0, 235)];
}
Try replacing this part of the code in FPPopoverController.m:
//ok, will be vertical
if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
with this code:
//ok, will be vertical
if (self.arrowDirection == FPPopoverNoArrow)
{
r.origin.x = p.x;
r.origin.y = p.y;
}
else if(ht == best_h || self.arrowDirection == FPPopoverArrowDirectionDown)
The reason you might be having this issue is that the macro FPPopoverArrowDirectionIsVertical considers a popover with no arrows as having a vertical arrow. So, the result is that is tries to best position your popover as close as possible to the view that triggered the popover.
If you replace the code as indicated above, you'll be creating a special case for popovers with no arrows and asking that the original points be respected without repositioning.
I have problem with vertical scroll in SPARK text area. I've added simple code in creation complete to insert 200 lines in text area:
private function creationCompleteHandler(event:FlexEvent):void
{
for (var iind:uint = 1; iind < 200; iind++)
{
testTextArea.text += iind.toString() + "\n";
}
}
And when I start application I noticed that the last 10% (approximately) of scroll bar is "a free walk". When scroll is on 90% page is scrolled all the way down, and when I move thumb of the scroll bar in last 10% of scroll bar nothing moves.
This is all until I change text in text area in browser, then scroll bar acts normal.
Thanks
edit: I tried to dispatch event "change", but it's still not working.
Try below, though it doesn't make much sense, at creationComplete block:
testTextArea.scroller.verticalScrollBar.value = testTextArea.scroller.verticalScrollBar.maximum;
testTextArea.validateNow();
testTextArea.scroller.verticalScrollBar.value = 0;
Then when you listen:
testTextArea.scroller.verticalScrollBar.addEventListener(Event.CHANGE, on Change);
You can do whatever you want with:
if(testTextArea.scroller.verticalScrollBar.value >= (testTextArea.scroller.verticalScrollBar.maximum-5))
This certainly looks hacky!