My app's UIScrollView Sliding automatic will bounce back,what can i do?
I do not want!
my code below:
- (void)initScrollView {
// a page is the width of the scroll view
sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 96, 320, 300)];
sv.contentSize = CGSizeMake(sv.frame.size.width * 3, sv.frame.size.height* 2);
sv.pagingEnabled = YES;
sv.clipsToBounds = YES;
sv.showsHorizontalScrollIndicator = NO;
sv.showsVerticalScrollIndicator = YES;
sv.scrollsToTop = NO;
sv.directionalLockEnabled = YES;
sv.delegate = self;
[self.view addSubview:sv];
currentPage = 0;
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
pageControl.backgroundColor = [UIColor clearColor];
[self createAllEmptyPagesForScrollView];
}
- (void)createAllEmptyPagesForScrollView {
tapView1 = [[UIView alloc]init];
tapView1.backgroundColor = [UIColor clearColor];
tapView1.frame = CGRectMake(320*0, 0, 320, sv.frame.size.height);
tapView2 = [[UIView alloc]init];
tapView2.backgroundColor = [UIColor clearColor];
tapView2.frame = CGRectMake(320*1, 0, 320, sv.frame.size.height);
tapView3 = [[UIView alloc]init];
tapView3.backgroundColor = [UIColor clearColor];
tapView3.frame = CGRectMake(320*2, 0, 320, sv.frame.size.height);
[sv addSubview:tapView1];
[sv addSubview:tapView2];
[sv addSubview:tapView3];
}
i konw why I slide up automatically bounce back,my code have problem!Not bove code!thanks everyone!
Related
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.backgroundColor = [UIColor redColor];
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = 1.0;
scrollView.clipsToBounds = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
self.view = scrollView;
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(50, 350, 50, 50);
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
I am new to iPhone software development. Please give me some code I could use here.
- (void)setupPage
{
UIView *blueView = [[UIView alloc] init];
blueView.frame = CGRectMake(0, 0, 640, 480);
blueView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:blueView];
self.pageControl.numberOfPages = 2;
[scrollView setContentSize:CGSizeMake(640, 0)];
}
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
if(pageControlIsChangingPage){
return;
}
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;
}
you can create array of UIViewControllers like bellow....
NSMutableArray *viewControllers;
and then just add the viewControllers or views with for loops like bellow...
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < 5; i++) {
[controllers addObject:yourViewControlls];// use different viewControls
}
self.viewControllers = controllers;
so here 5 viewConreoller are added in array and use it in PageViewController
for more info see this tutorial and example..
pagecontrol-example-in-iphone
I Have a collection of views in a view controller. by touching one of those views I would like to load specific data, for ex. a webpage into a web view that is on the same view controller
How would you accomplish that?
Thank you in advance
Here is my code with does not want to work:
UIView *categoryTitle = [[UIView alloc] initWithFrame:CGRectMake(0, 166 * counter
, 500, 20)];
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 20)];
[categoryLabel setBackgroundColor:[UIColor clearColor]];
NSMutableArray *allCurrentNews = [[News alloc] allNewsFromCategory:cat.CategoryId];
categoryLabel.text = cat.Name;
categoryLabel.textColor = [UIColor whiteColor];
[categoryTitle addSubview:categoryLabel];
UIColor *myblack = [[UIColor alloc] initWithRed:0.14 green:0.14 blue:0.14 alpha:1];
UIColor *ligheterBlac = [[UIColor alloc] initWithRed:0.227 green:0.22 blue:0.22 alpha:1];
[categoryTitle setBackgroundColor:myblack];
UIScrollView *tempScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 166 * counter, 500, 166)];
UIColor *tempcolor = ligheterBlac;
tempScroll.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor;
tempScroll.layer.borderWidth = 0.5f;
int countnews = 0;
for (News *news in allCurrentNews)
{
UIView *newsContainer = [[UIView alloc] initWithFrame:CGRectMake(160 * countnews, 30, 156, 126)];
newsContainer.tag = countnews + 1;
[newsContainer addGestureRecognizer:recognizer];
//newsContainer.NewsId = news.NewsId;
LazyImageView *image = [[LazyImageView alloc] initWithURl:[NSURL URLWithString:news.Thumbnail]];
image.frame = CGRectMake(0, 0 , 156, 96);
UILabel *newsTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 96, 156, 30)];
newsTitle.backgroundColor = myblack;
newsTitle.numberOfLines = 2;
newsTitle.font = [UIFont systemFontOfSize:11];
newsTitle.text = news.Title;
newsTitle.textColor = [UIColor whiteColor];
newsTitle.textAlignment = UITextAlignmentCenter;
newsContainer.layer.borderColor = [UIColor colorWithRed:0.34 green:0.34 blue:0.34 alpha:1].CGColor;
newsContainer.layer.borderWidth = 0.5f;
[newsContainer addSubview:image];
[newsContainer addSubview:newsTitle];
countnews ++;
[tempScroll setContentSize:CGSizeMake(allCurrentNews.count * 156, 96)];
[tempScroll addSubview:newsContainer];
//[image release];
}
[tempScroll setBackgroundColor: tempcolor];
[categories addSubview:tempScroll];
[categories addSubview:categoryTitle];
[tempcolor release];
[tempScroll release];
counter ++;
}
self.detailsView.layer.masksToBounds = NO;
self.detailsView.layer.shadowOffset = CGSizeMake(-10, 5);
self.detailsView.layer.shadowRadius = 5;
self.detailsView.layer.shadowOpacity = 0.3;
[self.view addSubview:categories];
[self.view addSubview:_detailsView];
[self.view addSubview:MainSubTitle];
[self.view addSubview:MainTitle];
Use the UITapGestureRecognizer.
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:selector(processTap:)];
UIView *targetView = //assign the view you need
targetView.tag = 5;
[targetView addGestureRecognizer:recognizer];
}
- (void)processTap:(UITapGestureRecognizer *)recognizer {
UIView *view = recognizer.view;
if (view.tag == 5) {
}
}
iPhone - 5.1(9B176)
I have been encountering inconsistent behaviour in overlaying a mask view on top of a UITableViewController as shown in picture below. Anyone encountered this behaviour, if yes, please suggest any solutions used?
Below is the code i have used to add mask view:
//Add the overlay view.
if(ovController == nil) {
NSString *cellIdentifier = #"overlayVC";
ovController = [[self storyboard] instantiateViewControllerWithIdentifier:cellIdentifier];
}
CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;
ovController.view.alpha = 0.85;
ovController.delegate = self;
UIView *aboveView = self.parentViewController.view;
[self.tableView insertSubview:ovController.view aboveSubview:aboveView];
I have also tried
`[self.tableView insertSubview:ovController.view aboveSubview:self.tableView]`
Hi use something like below code
-(void) showLoadingView {
//NSLog(#">>>>>>>>>>>>>>>>> loading view Landscape right ");
if (loadView == nil) {
loadView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadView.opaque = NO;
loadView.backgroundColor = [UIColor clearColor];
//loadView.alpha = 0.8;
viewBack = [[UIView alloc] initWithFrame:CGRectMake(95, 230, 130, 40)];
viewBack.backgroundColor = [UIColor blackColor];
viewBack.alpha = 0.7f;
viewBack.layer.masksToBounds = NO;
viewBack.layer.cornerRadius = 8;
spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5.0, 5.0, 30.0, 30.0)];
[spinningWheel startAnimating];
// spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[viewBack addSubview:spinningWheel];
[spinningWheel release];
UILabel *lblLoading = [[UILabel alloc] initWithFrame:CGRectMake(23, 6, 110, 25)];
lblLoading.backgroundColor = [UIColor clearColor];
lblLoading.font = [UIFont fontWithName:#"Helvetica-Bold" size:16.0];
lblLoading.textAlignment = UITextAlignmentCenter;
lblLoading.textColor = [UIColor whiteColor];
lblLoading.text = #"Loading...";
[viewBack addSubview:lblLoading];
[loadView addSubview:viewBack];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
loadView.frame = iphoneFrame;
viewBack.frame = loadiPhone;
}
else
{
loadView.frame = ipadFrame;
viewBack.frame = loadiPad;
}
[self.window addSubview:loadView];
}
-(void) hideLoadingView {
[loadView removeFromSuperview];
}
declare this methods in you APPdelegate class so you can call it from any view in your code.
here i have set a view over the window not in view this surelu solve your problem!!!!
I have multiple photos in an NSArray and i want to display them with the swipe gesture in full size without using Three20 . so how can i do that?
Use a scrollView for accomplish that :
UIScrollView * scroller = [[[UIScrollView alloc] initWithFrame:CGTectMake(0, 0, 320, 480)] autorelease];
scroller.pagingEnabled = YES;
[self.view addSubview:scroller];
int x = 0;
for (int i = 0; i < [yourArray count]; i++){
UIImageView * myImageview = [[[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 320, 480)] autorelease];
[myImageview setImage:[yourArray objectAtIndex:i]];
[scroller addSubview:myView];
x += myView.frame.size.width;
}
[scroller setContentSize:CGSizeMake(x, 480)];
This Code works for me great:
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
[awesomeView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
[scroll release];
I just want to scroll only one page then to another.
I set m_pScrollView.pagingEnabled = YES and m_pScrollView.bounces = NO but when I scroll to the edge of the page it goes out of the page range and then back, likes an inertia effect.
I just want it scoll only one page not more. Can anyone help me?
- (void)viewDidLoad {
[super viewDidLoad];
m_pScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
m_pScrollView.delegate = self;
m_pScrollView.contentSize = CGSizeMake(768 * 3, 1024);
m_pScrollView.pagingEnabled = YES;
m_pScrollView.bounces = NO;
m_pScrollView.alwaysBounceHorizontal = NO;
m_pScrollView.alwaysBounceVertical = NO;
Myview *myview = [[Myview alloc]initWithFrame:CGRectMake(0, 0, 768, 1024)];
myview.backgroundColor = [UIColor redColor];
Myview *myview2 = [[Myview alloc]initWithFrame:CGRectMake(768, 0, 768, 1024)];
myview2.backgroundColor = [UIColor blueColor];
Myview *myview3 = [[Myview alloc]initWithFrame:CGRectMake(768 * 2, 0, 768, 1024)];
myview3.backgroundColor = [UIColor grayColor];
[m_pScrollView addSubview:myview];
[m_pScrollView addSubview:myview2];
[m_pScrollView addSubview:myview3];
[self.view addSubview:m_pScrollView];
}
You have to set the content size like this
m_pScrollView.contentSize = CGSizeMake(x,y);
For more about this Create UIScrollview programmatically