Typically, if one is using SWRevealViewController, the front view fully covers the rear view, and the rear view is visible only if some action is performed (swipe, tap etc). My requirement is that the rear view should always be visible at least a little bit when the view loads and when the user swipes back. I tried modifying the frame of the frontView to achieve this, but I saw no effect whatsoever.
I put the frame update frame code in a method:
-(void)updateFrontViewControllerFrameWithPadding:(BOOL)bProvidePadding
{
if (!bProvidePadding) {
CGRect frontViewControllerFrame = self.frontViewController.view.bounds;
CGFloat xOrigin = self.view.bounds.origin.x;
CGFloat nWidth = self.view.bounds.size.width;
frontViewControllerFrame.origin.x = xOrigin;
frontViewControllerFrame.size.width = nWidth;
self.frontViewController.view.frame = frontViewControllerFrame;
_frontViewShadowColor = [UIColor blackColor];
[_contentView reloadShadow];
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 20.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 15.0f;
nPadding = _rearViewRevealWidthIphone;
}
CGRect revealViewBounds = self.view.bounds;
CGFloat frontViewXPos = revealViewBounds.origin.x + nPadding;
CGFloat frontViewWidth = revealViewBounds.size.width - nPadding;
CGRect frontViewFrame = self.frontViewController.view.frame;
frontViewFrame.origin.x = frontViewXPos;
frontViewFrame.size.width = frontViewWidth;
self.frontViewController.view.frame = frontViewFrame;
_frontViewShadowColor = [UIColor colorWithWhite:0.5
alpha:0.5];
[_contentView reloadShadow];
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
This method is called from the viewWillLayoutSubviews method, with providePadding argument as TRUE. This method also needs to be called from places in SWRevealViewController where pan and tap gestures have been handled.
This is how the view looks when swiped:
This is the solution to the frame resizing problem:
-(void)updateFrontViewControllerFrameWithPadding:(BOOL)bProvidePadding
{
if (!bProvidePadding) {
CGRect frontViewControllerFrame = self.frontViewController.view.bounds;
CGFloat xOrigin = self.view.bounds.origin.x;
CGFloat nWidth = self.view.bounds.size.width;
frontViewControllerFrame.origin.x = xOrigin;
frontViewControllerFrame.size.width = nWidth;
self.frontViewController.view.frame = frontViewControllerFrame;
_frontViewShadowColor = [UIColor blackColor];
[_contentView reloadShadow];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f].CGColor;
frontViewLayer.shadowOpacity = 0.0f;
frontViewLayer.shadowOffset = CGSizeMake(0.0f, 0.0f);
frontViewLayer.shadowRadius = 0.0f;
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 60.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 35.0f;
nPadding = _rearViewRevealWidthIphone;
}
CGRect revealViewBounds = self.view.bounds;
CGFloat frontViewXPos = revealViewBounds.origin.x + nPadding;
CGFloat frontViewWidth = revealViewBounds.size.width - nPadding;
CGRect frontViewFrame = self.frontViewController.view.frame;
frontViewFrame.origin.x = frontViewXPos;
frontViewFrame.size.width = frontViewWidth;
self.frontViewController.view.frame = frontViewFrame;
[self rearViewDeploymentForLeftPosition];
_frontViewShadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f];
[_contentView reloadShadow];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor blackColor].CGColor;
frontViewLayer.shadowOpacity = _frontViewShadowOpacity;
frontViewLayer.shadowOffset = _frontViewShadowOffset;
frontViewLayer.shadowRadius = _frontViewShadowRadius;
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
This also takes into account the shadow related problem mentioned above.
This method needs to be called from appropriate places, eg; when the view loads initially, when pan or tap gestures are performed etc.
Related
I am trying to repurpose this plotting widget, and in particular I am trying to put 3 plots in one custom UIViewController. I am finding that the first two I process/add to my self.view are fine, but for the third view the following doesn't work
-(void) drawLineFrom:(CGPoint) start to: (CGPoint)end {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, start.x, start.y);
CGContextAddLineToPoint(context,end.x,end.y);
}
- (void)drawRect:(CGRect)rect
{
...
if([self.dictDispPoint count] > 0)
{
// remove loading animation
[self stopLoading];
float range = self.max-self.min;
float intervalHlines = (self.chartHeight)/MIN(intervalLines, self.dictDispPoint.count - 1); //5.0f;
float intervalValues = range/MIN(intervalLines, self.dictDispPoint.count - 1); //5.0f;
// horizontal lines
for(int i=intervalLines;i>0;i--)
{
[self setContextWidth:0.5f andColor:linesColor];
CGPoint start = CGPointMake(self.leftMargin, (self.chartHeight+topMargin-i*intervalHlines-6));
CGPoint end = CGPointMake(self.chartWidth+self.leftMargin, (self.chartHeight+topMargin-i*intervalHlines-6));
// draw the line
[self drawLineFrom:start to:end]; // This line doesn't seem to run?!?
// draw prices on the axis
NSString *prezzoAsse = [self formatNumberWithUnits:(self.min+i*intervalValues)/valueDivider withFractionDigits:0];
CGPoint prezzoAssePoint = CGPointMake(self.leftMargin - [self sizeOfString:prezzoAsse withFont:systemFont].width - 5,(self.chartHeight+topMargin-i*intervalHlines-6));
[self drawString:prezzoAsse at:prezzoAssePoint withFont:systemFont andColor:linesColor];
[self endContext];
}
...
}
In particular, I have verified that the for loop runs the requisite number of times and that all the variables have non-null sensible values. And the drawString function is working as expected, but somehow the horizontal lines I should be seeing never show up in the third instance of this custom view class.
Printing all variable + line color...these are all non-null, sensible
Changing the order of the graphs...it's always the 3rd graph (haven't tried more than 3) that has a problem
Changing the data in the graph...the problem is there regardless of what data I supply to make the graph
Cleaning the build, trying different iPhones in the simular...yup, this doesn't change the performance
I don't have much experience with Quartz. Can anyone tell me if I am missing some traps for the unweary? Is there some threading problem when multiple views are draw simultaneously? What else could I try to trouble-shoot this?
Here is code showing how the plots are created and laid out on the screen:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Your recent runs";
/********** Creating an area for the graph ***********/
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
self.width = screenWidth;
self.height = screenRect.size.height;
CGRect frame = CGRectMake(0, self.height*.15, screenWidth, self.height*.25);
// initialization
self.distancePlot = [[ZFPlotChart alloc] initWithFrame:frame];
self.distancePlot.units = self.distanceUnits;
[self.view addSubview:self.distancePlot];
frame.origin.y += self.height*.05 + frame.size.height;
self.timePlot = [[ZFPlotChart alloc] initWithFrame:frame];
self.timePlot.units = self.timeUnits;
[self.view addSubview:self.timePlot];
//THIS IS THE PLOT FOR WHICH THE LINE-DRAWING CODE DOESN'T PRODUCE ANY VISIBLE LINES
frame.origin.y += self.height*.05 + frame.size.height;
self.ratePlot = [[ZFPlotChart alloc] initWithFrame:frame];
self.ratePlot.units = self.rateUnits;
[self.view addSubview:self.ratePlot];
self.distancePlot.alpha = 0;
self.timePlot.alpha = 0;
self.ratePlot.alpha = 0;
CGFloat heightAdd = frame.size.height;
frame = CGRectMake(0, self.height*.14, self.width, self.height*.03);
...some here creates UILabels above each plot....
frame.origin.y += self.height*.05 + heightAdd;
UILabel *rateLabel = [[UILabel alloc] initWithFrame:frame];
rateLabel.text = #"Rate";
rateLabel.textColor = [UIColor darkBlue];
rateLabel.alpha = 0;
rateLabel.font = [UIFont fontWithName:SYSTEM_FONT_TYPE size:SYSTEM_FONT_SIZE];
rateLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:rateLabel];
// draw data
[self.distancePlot createChartWith:self.distancePoints];
[self.timePlot createChartWith:self.timePoints];
[self.ratePlot createChartWith:self.ratePoints];
[UIView animateWithDuration:0.5 animations:^{
self.distancePlot.alpha = 1.0;
self.timePlot.alpha = 1.0;
self.ratePlot.alpha = 1.0;
distanceLabel.alpha = 1.0;
timeLabel.alpha = 1.0;
rateLabel.alpha = 1.0;
}];
}
In one of my views I have a bottom bar. A tap on this view animates a temporary cart half way to the screen. Now, where there is no item in the temporary table I show a no data overlay which is nothing but a view with an empty cart image and text underneath it.
The issue is: when this table animates to expand and collapse, the no data overlay does not look good during animation. It appears that the image is also shrinking/expanding until the temporary table view stops animating.
So, I tried by playing with the alpha of the temporary table view while this animation happens so that it does not look that bad. But this is not helping either. There is an abrupt flash in the end.
Any suggestions?
self.temporaryTable.backgroundView = self.noDataOverlay;
[UIView animateWithDuration:0.5 animations:^{
self.temporaryTable.alpha = 0.5;
} completion:^(BOOL finished) {
self.temporaryTable.alpha = 1.0;
}];
Here is my code for drawing the image:
- (void)drawRect:(CGRect)iRect scalingImage:(BOOL)iShouldScale {
CGRect aRect = self.superview.bounds;
// Draw our image
CGRect anImageRect = iRect;
if (self.image) {
//scale the image based on the height
anImageRect = CGRectZero;
anImageRect.size.height = self.image.size.height;
anImageRect.size.width = self.image.size.width;
#ifdef ACINTERNAL
if (iShouldScale) {
anImageRect = [self aspectFittedRect:anImageRect max:aRect];
} else {
anImageRect.origin.x = (iRect.size.width/2) - (anImageRect.size.width/2);
anImageRect.origin.y = kTopMargin;
}
#else
anImageRect.origin.x = (iRect.size.width/2) - (anImageRect.size.width/2);
anImageRect.origin.y = kTopMargin;
#endif
if (self.shouldCenterImage)
anImageRect.origin.y = (iRect.size.height/2) - (anImageRect.size.height/2);
[self.image drawInRect:anImageRect];
} else {
anImageRect.origin.y = (iRect.size.height/6);
anImageRect.size.height = (iRect.size.height/6);
}
// Draw our title and message
if (self.title) {
CGFloat aTop = anImageRect.origin.y + anImageRect.size.height + kSpacer;
CGFloat aWidth = aRect.size.width;
UIColor *aColor = [UIColor colorWithRed:96/256.0 green:106/256.0 blue:122/256.0 alpha:1];
[aColor set];
CGRect aTextRect = CGRectMake(0, aTop, aWidth, kTitleHeight * 2);
UIFont *aTitleFont = [UIFont boldSystemFontOfSize:kTitleFontSize];
[self.title drawInRect:aTextRect withFont:aTitleFont lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];
if (self.subTitle) {
UIFont *aSubTitleFont = [UIFont systemFontOfSize:kSubTitleFontSize];
aTextRect = CGRectMake(0, aTop+kSpacer, aWidth, kTitleHeight);
[self.subTitle drawInRect:aTextRect withFont:aSubTitleFont lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];
}
}
}
- (void)addToView:(UIView *)iView {
// setting a unique tag number here so that if the user has any other tag there should not be a conflict
UIView *aView = [iView viewWithTag:699];
if (aView) {
[aView removeFromSuperview];
}
self.tag = 699;
[iView addSubview:self];
}
- (void)removeView {
[super removeFromSuperview];
}
-(void)setViewFrame:(CGRect) iFrame {
CGRect aRect = self.frame;
aRect.size.width = iFrame.size.width;
aRect.size.height = iFrame.size.height;
self.frame = aRect;
[self setNeedsDisplay];
}
- (CGRect)aspectFittedRect:(CGRect)iRect max:(CGRect)iMaxRect {
float anOriginalAspectRatio = iRect.size.width / iRect.size.height;
float aMaxAspectRatio = iMaxRect.size.width / iMaxRect.size.height;
CGRect aNewRect = iMaxRect;
if (anOriginalAspectRatio > aMaxAspectRatio) { // scale by width
aNewRect.size.height = iMaxRect.size.width * iRect.size.height / iRect.size.width;
} else {
aNewRect.size.width = iMaxRect.size.height * iRect.size.width / iRect.size.height;
}
aNewRect.origin.y = (iMaxRect.size.height - aNewRect.size.height)/2.0;
aNewRect.origin.x = (iMaxRect.size.width - aNewRect.size.width)/2.0;
return CGRectIntegral(aNewRect);
}
One possibility here is to fix the original problem, namely the fact that the empty cart image is expanding/collapsing as the view animates. Without seeing your code it is difficult to solve this problem, but in my own code what I do is set the contentMode of the UIImageView to UIViewContentModeBottom. This causes the image to stay the same size even though the image view that contains it may grow and shrink as part of the animation.
You see a flash because you animate alpha up to 0.5 and then when animation completes you set it from 0.5 to 1.0. Just animate the alpha up to 1.0:
[UIView animateWithDuration:0.5
animations:^
{
self.temporaryTable.alpha = 1.0;
}];
My table view cells contain a circle in an UIView, indicating a value. I want to add the UIKit Dynamics attachment behaviour to that circle in order to for it to lag a bit when scrolling.
I don't want to attach the individual cells to each other but only the circle view to the UITableViewCell. The rest of the cell should scroll as usual.
Problem: The UITableViewCell has its origin always at (0, 0). How can I add the circle to a view that actually does move when scrolling?
I finally got it to work. The UITableView moves the coordinate system of every cell and of all views contained within that cell. Therefor I needed to manually move my view inside the UITableViewCell during scrolling while still referring to the initial anchor point.
The table view controller:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
BOOL scrollingUp = '\0';
if (self.lastContentOffset > scrollView.contentOffset.y) {
scrollingUp = YES;
}
else if (self.lastContentOffset < scrollView.contentOffset.y) {
scrollingUp = NO;
}
NSInteger offset = 64; // To compensate for the navigation bar.
if (scrollingUp) {
offset = offset - scrollView.contentOffset.y;
}
else {
offset = offset + scrollView.contentOffset.y;
}
// Limit the offset so the views will not disappear during fast scrolling.
if (offset > 10) {
offset = 10;
}
else if (offset < -10) {
offset = -10;
}
// lastContentOffset is an instance variable.
self.lastContentOffset = scrollView.contentOffset.y;
for (UITableViewCell *cell in self.tableView.visibleCells) {
// Use CoreAnimation to prohibit flicker.
[UIView beginAnimations:#"Display notification" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationBeginsFromCurrentState:YES];
cell.view.frame = CGRectMake(cell.view.frame.origin.x, offset, cell.view.frame.size.width, cell.view.frame.size.height);
[UIView commitAnimations];
[cell.dynamicAnimator updateItemUsingCurrentState:cell.view];
}
}
The table view cell:
-(void)layoutSubviews {
[super layoutSubviews];
// _view is the animated UIView.
UIDynamicItemBehavior *viewBehavior = [[UIDynamicItemBehavior alloc] initWithItems:#[_view]];
viewBehavior.elasticity = 0.9f;
UIAttachmentBehavior *attachmentBehaviorView = [[UIAttachmentBehavior alloc] initWithItem:_view attachedToAnchor:CGPointMake(_anchorView.frame.origin.x + _anchorView.frame.size.width / 2.0f, _anchorView.frame.origin.y + _anchorView.frame.size.height / 2.0f)];
attachmentBehaviorView.damping = 8.0f;
attachmentBehaviorView.frequency = 4.0f;
attachmentBehaviorView.length = 0.0f;
[_dynamicAnimator addBehavior:viewBehavior];
[_dynamicAnimator addBehavior:attachmentBehaviorView];
}
You can change the anchorPoint of UIAttachmentBehavior during -[scrollViewDidScroll:]. You may refer to the following code snippet:
- (void)viewDidLoad
{
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UIAttachmentBehavior *behavior1 = [[UIAttachmentBehavior alloc] initWithItem:self.circleView
attachedToAnchor:[self tableViewAnchor]];
behavior1.length = 10.0;
behavior1.damping = 0.3;
behavior1.frequency = 2.5;
[animator addBehavior:behavior1];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
behavior1.anchorPoint = [self.tableView convertPoint:[self tableViewAnchor] toView:self.view];
}
- (CGPoint)tableViewAnchor
{
return CGPointMake(160.0, 154.0); // return your target coordination w.r.t. the table view
}
Preview:
Design:
View Hierarchy is as below:
UIScrollView (for paging multiple image)
UIScrollView (for enabling zoom on the UIImageView)
UIImageView
UIView (origin,size relative to UIImage in UIImageView)
UIView
UIView ...
UIScrollview
UIImageView
UIView
UIView ...
UIScrollView ... and so on
Implementation:
- (id)init
{
self = [super init];
if (self) {
// Custom initialization
self.minimumZoomScale = 1.0f;
self.maximumZoomScale = 4.0f;
self.zoomScale = 1.0f;
self.bouncesZoom = true;
self.bounces = true;
self.tag = 10;
self.alwaysBounceHorizontal = false;
self.autoresizesSubviews = YES;
self.zoomView = [[UIImageView alloc] init];
self.zoomView.userInteractionEnabled = YES;
self.zoomView.autoresizesSubviews = YES;
}
return self;
}
- (void)displayImage:(UIImage *)image
{
// Set the image in the view
[_zoomView setImage:image];
// Set the Frame size to the size of image size
// Ex. Resulting ScrollView frame = {0,0},{1250,1500}
// Ex. Resulting ImageView frame = {0,0}, {1250,1500}
CGRect scrollFrame = self.frame;
scrollFrame.size.width = image.size.width;
scrollFrame.size.height = image.size.height;
self.frame = scrollFrame;
CGRect iViewFrame = _zoomView.frame;
iViewFrame.size.width = image.size.width;
iViewFrame.size.height = image.size.height;
_zoomView.frame = iViewFrame;
// Add subviews before resetting the contentsize
for (customClass* field in list.fields) {
UIView* view = [[UIView alloc] initWithFrame:CGRectMake([field.x floatValue], [field.y floatValue], [field.width floatValue], [field.height floatValue])];
view.backgroundColor = [UIColor redColor];
view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_zoomView addSubview:view];
}
// Set the Frame size to the size of scrollview frame size
// Ex. Resulting ScrollView Frame = {0,0},{320,460}
// Ex. Resulting ImageView Frame = {0,0},{320,460}
CGRect scrollViewFrame = self.frame;
scrollViewFrame.size.width = 320.0f;
scrollViewFrame.size.height = 460.0f;
self.frame = scrollViewFrame;
CGRect imageViewFrame = _zoomView.frame;
imageViewFrame.size.width = self.bounds.size.width;
imageViewFrame.size.height = self.bounds.size.height;
_zoomView.frame = imageViewFrame;
self.contentSize = _zoomView.bounds.size;
[self addSubview:_zoomView];
}
Above is the code that I tried implementing. It adds the UIViews to the UIImageView inside the UIScrollView. But the relative origin of the UIView is not correct (both before and after resizing).
Is there anything I should be doing differently to get the UIViews correctly placed inside the UIImageView?
This was top hit on Google for "scrollview subviews wont resize". For anyone else following that link:
Looking at your source, and comparing to mine, I realised that in Interface Builder, my NIB file had the tickbox for "auto size subviews" unticked. I have a vague memory this might be because in an old version of Xcode (this is an old project that's been maintained for a while) ... UIScrollView defaulted to having it switched off.
So: check that you've got it set correctly in Xcode / Interface Builder, and/or that you're setting it in code.
i have a segmented control with 4 segment
segment 1 - i need a page control to swipe through photos <- -> left & right. 1- 4 photos max
Segment 2 & 3 - i need a table view
Segment 4 - i need it to be able to play video
i'm currently doing this
- (IBAction)infoAction:(id)sender {
NSString * selectedTitle = [info titleForSegmentAtIndex:[info selectedSegmentIndex]];
NSLog(#"Selected Title = %#",selectedTitle);//test
switch ([info selectedSegmentIndex])
{ case 0:
{
test.text = [frogInfo.imageFiles objectAtIndex:0];
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:#"Detail1Temp.png"]];
break;
}
case 1:
{
test.text = frogInfo.description;
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:#"Detail2Temp.png"]];
break;
}
case 2:
{
test.text = frogInfo.distribution;
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:#"Detail3Temp.png"]];
break;
}
case 3:
{
test.text = [frogInfo.videoFiles objectAtIndex:0];
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:#"Detail4Temp.png"]];
break;
}
}
}
picture with page control
section tableview
Based on what i will like to do, is it possible ? in this switch case function ?
can anybody show or have any link to tutorial on how to work out the page control swiping ?
thanks for reading
Des
I have done something very similar although I used a UISlider instead of segmented control - What you need is a pageable UISCrollview with 4 equal sized pages (UIViews) loaded horizontally one after another if take-up the entire width of an iPhone each page is 320 wide and the content size width of your scrollview will be 1280. Tie up the UIsegmented controls to scroll the pages programatically:
assuming a page width of 320:
-(IBAction)movepage:(id)sender {
int xloc = (segmentedController.selectedSegmentIndex * 320);
CGRect fieldrect = CGRectMake(xloc,0,320, pagesize.height);
[scrollView scrollRectToVisible:fieldrect animated:YES];
}
To load the scrollview and manage the pagecontroller:
pagectrl.numberOfPages = 4;
pagectrl.currentPage = 0;
scrollView.pagingEnabled = YES;
scrollView.contentSize=CGSizeMake(320* pagectrl.numberOfPages, 500);
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.bouncesZoom = NO;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
search_url.delegate = self;
user.delegate = self;
password.delegate = self;
rpc_code.delegate = self;
// add pages
int page = 0;
CGRect frame = scrollView.frame;
pagesize = frame.size.width;
frame.origin.y = 0;
frame.origin.x = frame.size.width * page;
firstView.frame = frame;
[scrollView addSubview:firstView];
page ++;
frame.origin.x = frame.size.width * page;
locsubView.frame = frame;
[scrollView addSubview:locsubView];
page ++;
frame.origin.x = frame.size.width * page;
QRgensubView.frame = frame;
[scrollView addSubview:QRgensubView];
page ++;
frame.origin.x = frame.size.width * page;
scansubView.frame = frame;
[scrollView addSubview:scansubView];
page ++;
frame.origin.x = frame.size.width * page;
symbologysubView.frame = frame;
[scrollView addSubview:symbologysubView];
[self registerForKeyboardNotifications];
CGRect fieldrect = CGRectMake(0,0,320, pagesize);
[scrollView scrollRectToVisible:fieldrect animated:YES]; //goto 1st page
}
Note you may need to control or manage the user ability to scroll the scroll view - you do that by setting up the scrollview delegate - the code below is not fitted to your exact requirement but I'm sure you can figure out the rest!
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
// if (pageControlUsed)
// {
// do nothing - the scroll was initiated from the page control, not the user dragging
// return;
// }
// Switch the indicator when more than 50% of the previous/next page is visible
int page = floor((scrollView.contentOffset.x - pagesize / 2) / pagesize) + 1;
pagectrl.currentPage = page;
// A possible optimization would be to unload the views+controllers which are no longer visible
}