My Sample code:
- (IBAction)captureButton:(id)sender {
captureButton.hidden = YES;
currImage = [signatureViewController imageWithView:self.view];
NSLog (#"image %#",currImage);
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(150,100,300,150)];
imgView.backgroundColor = [UIColor blackColor];
imgView.image = currImage;
[self.view addSubview:imgView];
image.image = nil;
}
My prob is capturebutton is geting hidden the view.. please help
Thanks in advance
Two options:
1) Add the following code to bring your image view to front:
[self.view bringSubviewToFront:imgView];
2) Hide your button:
[(UIButton *)sender setHidden:YES];
Try this,
yourButton.hidden = YES;
You could just try disabling the button.
If it is hidden behind a view this may help.
yourbutton.enabled = NO;
Related
I loaded a pdf in a scrollview, and I would like to go directly to the next page without having the animation scrolling.
CGRect scrollViewRect = CGRectInset(viewRect, -scrollViewOutset, 0.0f);
theScrollView = [[UIScrollView alloc] initWithFrame:scrollViewRect]; // All
theScrollView.autoresizesSubviews = NO;
theScrollView.contentMode = UIViewContentModeRedraw;
theScrollView.showsHorizontalScrollIndicator = NO;
theScrollView.showsVerticalScrollIndicator = NO;
theScrollView.scrollsToTop = NO;
theScrollView.delaysContentTouches = NO;
theScrollView.pagingEnabled = YES;
theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
theScrollView.backgroundColor = [UIColor clearColor];
theScrollView.delegate = self;
[self.view addSubview:theScrollView];
Is it possible ?
You have to use below method to jump on direct offset of your next page by below method.
[objUIScrollView setContentOffset:CGPointMake(YOUR_X, YOUR_Y) animated:NO]
animated = NO;
If you are loading PDF through WebView than you need to follow below code:
webview.scrollView.contentOffset = CGPointMake(YOUR_X, YOUR_Y);
Note : Use this above code in your Next Button page or after loading
WebView properly may be in below method.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
}
Hope this will work as you expected.
Sure, simply use:
[theScrollView scrollRectToVisible:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f) animated:NO];
or
[theScrollView setContentOffset:CGPointMake(0.0f, 0.0f) animated:NO];
and change the CGPoint or CGRect to the offset of the page of your liking.
I have a scrollview(timesScrollView) which is added as a subview on a view(dropDownView).The view is hidden until a particular button is pressed, when that button is pressed view will appear.
(IBAction)how_many_times_btn_click:(id)sender{
if(howMany==false){
for(UIView *view in dropDownView.subviews)
{
[view removeFromSuperview];
}
howMany=true;
duration=false;
how_many_times_btn.backgroundColor=[UIColor colorWithRed:130/255.0f green:189/255.0f blue:31/255.0f alpha:1.0f];
durationBtn.backgroundColor=[UIColor colorWithRed:62/255.0f green:67/255.0f blue:79/255.0f alpha:1.0f];
startBtn.backgroundColor=[UIColor colorWithRed:62/255.0f green:67/255.0f blue:79/255.0f alpha:1.0f];
dropDownView.hidden=NO;
dropDownView.frame=CGRectMake(0, 0, self.view.frame.size.width,70);
dropDownView.backgroundColor=[UIColor colorWithRed:37/255.0f green:42/255.0f blue:54/255.0f alpha:1.0f];
//dropDownView.backgroundColor=[UIColor whiteColor];
targetLbl=[[UILabel alloc]init];
targetLbl.frame=CGRectMake(0, 30, dropDownView.frame.size.width,30);
targetLbl.text=#"TARGET";
targetLbl.textColor=[UIColor whiteColor];
targetLbl.font=[UIFont boldSystemFontOfSize:22];
targetLbl.textAlignment=NSTextAlignmentCenter;
how_many_Lbl=[[UILabel alloc]init];
how_many_Lbl.frame=CGRectMake(0, targetLbl.frame.origin.y+targetLbl.frame.size.height, dropDownView.frame.size.width, 20);
how_many_Lbl.textAlignment=NSTextAlignmentCenter;
how_many_Lbl.text=#"HOW MANY TIMES WILL YOU DO IT?";
how_many_Lbl.textColor=[UIColor colorWithRed:65/255.0f green:71/255.0f blue:80/255.0f alpha:1.0f];
how_many_Lbl.font=[UIFont systemFontOfSize:10.0f];
hideViewBtn=[UIButton buttonWithType:UIButtonTypeCustom];
hideViewBtn.frame=CGRectMake(dropDownView.frame.size.width-30,20,20,20);
[hideViewBtn setImage:[UIImage imageNamed:#"Close Icon [ x ]"] forState:UIControlStateNormal];
[hideViewBtn addTarget:self action:#selector(hideView) forControlEvents:UIControlEventTouchUpInside];
//hideViewBtn.backgroundColor=[UIColor whiteColor];
self.timesScroll=[[LTInfiniteScrollView alloc] initWithFrame:CGRectMake(0, how_many_Lbl.frame.origin.y+how_many_Lbl.frame.size.height+16, dropDownView.frame.size.width, 102)];
//self.timesScroll.backgroundColor=[UIColor whiteColor];
self.timesScroll.verticalScroll=NO;
self.timesScroll.dataSource=self;
self.timesScroll.maxScrollDistance=5;
self.timesScroll.contentInset=UIEdgeInsetsMake(0, self.timesScroll.frame.size.width/2-31, 0,self.timesScroll.frame.size.width/2-31 );
self.timesScroll.userInteractionEnabled=YES;
self.timesScroll.exclusiveTouch=YES;
dropDownView.frame=CGRectMake(0, 0, self.view.frame.size.width,_timesScroll.frame.origin.y+_timesScroll.frame.size.height+20);
[self viewWillAppear:YES];
[dropDownView addSubview:targetLbl];
[dropDownView addSubview:how_many_Lbl];
[dropDownView addSubview:hideViewBtn];
[dropDownView addSubview:_timesScroll];
}
else
{
[self hideView];
}
}
The method above is what I am using to create view.
Now my problem is that when that particular button(how_many_times_btn) is pressed again all views are first removed then added as you can see and scrollview starts from initial position but I want it show from where I left it last time how_many_times_btn was clicked.
Hope you can understand What I am trying to say....if not I am happy to elaborate furthur.
you can get the last position by delegate methods
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
nslog(#"%f %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
}
and store the x and y value and set
scrollView.contentOffset = CGPointMake(x,y);
You can save contentOffsetto one variable of CGPoint. And use this variable 's value later to scroll the UIScrollview.
Something like below line of code :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
contentOffset = scrollView.contentOffset;
}
When button pressed write below line of code:
self.timesScroll .contentOffset = contentOffset;
I'm using LTInfiniteScrollview in which there is a method 'reloadDataWithInitialIndex'
-(void)reloadDataWithInitialIndex:(NSInteger)initialIndex
{
for (UIView *view in self.scrollView.subviews) {
[view removeFromSuperview];
}
self.views = [NSMutableDictionary dictionary];
self.visibleViewCount = [self.dataSource numberOfVisibleViews];
self.totalViewCount = [self.dataSource numberOfViews];
[self updateSize];
_currentIndex = initialIndex;
self.scrollView.contentOffset = [self contentOffsetForIndex:_currentIndex];
[self reArrangeViews];
[self updateProgress];}
This method is called in 'viewWillAppear'
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.viewSize = CGRectGetWidth(self.view.frame) / Number_of_visibleViews;
self.timesScroll.delegate=self;
[self.timesScroll reloadDataWithInitialIndex:howIndex];}
I just passed previous index value here.
I am new to using MapView in iOS, here's my situation:
When I toggle the nearby button it will redirect me to map view:
Then when I toggle the List View button, it will display a UItableView with a Map Button. Then finally, when I toggle the map button it will display the Map View.
My problem is, when in list view then I scrolled down then toggle the map view button the map view doesn't fill the whole screen (please see image for reference):
Here's what i have so far:
This is how i initiate the Map:
- (void)viewDidLoad {
jobsMapView = [[MTJobsMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
jobsMapView.showsUserLocation = YES;
jobsMapView.zoomEnabled = YES;
jobsMapView.rotateEnabled = NO;
jobsMapView.parentViewController = self;
jobsMapView.delegate = jobsMapView;
// Set up buttons but hide them
showListViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
showListViewButton.frame = CGRectMake(self.view.frame.size.width-58, self.view.frame.size.height-159, 50.0, 36.0);
[showListViewButton addTarget:self action:#selector(toggleNearbyView:) forControlEvents:UIControlEventTouchUpInside];
[showListViewButton setImage:[UIImage imageNamed:#"list.png"] forState:UIControlStateNormal];
[self.view addSubview:showListViewButton];
showMapViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
showMapViewButton.frame = CGRectMake(self.view.frame.size.width-58, self.view.frame.size.height-159, 50.0, 36.0);
[showMapViewButton addTarget:self action:#selector(toggleNearbyView:) forControlEvents:UIControlEventTouchUpInside];
[showMapViewButton setImage:[UIImage imageNamed:#"icon_map.png"] forState:UIControlStateNormal];
[self.view addSubview:showMapViewButton];
// Default mapView is shown in Nearby View
showListViewButton.hidden = YES;
showListViewButton.enabled = NO;
showMapViewButton.hidden = YES;
showMapViewButton.enabled = NO;
self.listViewSelected = NO;
}
- (IBAction)toggleNearbyView:(UIButton *)sender {
self.listViewSelected = !self.listViewSelected;
if (self.listViewSelected) {
self.title=[NSString stringWithFormat:#"Nearby Jobs (%d)",[[self.jobsDictionary objectForKey:#"sub_slots"] count]];
// TableView is shown, so showMapViewButton for user to select MapView
showMapViewButton.hidden = NO;
showMapViewButton.enabled = YES;
showListViewButton.hidden = YES;
showListViewButton.enabled = NO;
[jobsMapView removeFromSuperview];
} else {
showListViewButton.hidden = NO;
showListViewButton.enabled = YES;
showMapViewButton.hidden = YES;
showMapViewButton.enabled = NO;
self.title=[NSString stringWithFormat:#"Nearby Jobs (%d)",[[self.FilterDictionary objectForKey:#"sub_slots"] count]];
[jobsMapView mapViewWithJobsDisplayed:self.FilterDictionary andUserLocation:xapp.self.userLocation andUserCoordinates:xapp.self.userLocationCoordinates];
[self.jobsTableView addSubview:jobsMapView];
}
}
what am doing wrong here?
Any help will be appreciated..
thanks...
Comment This line.
self.listViewSelected = !self.listViewSelected;
in toggleNearbyView method
When i press the back button. the iCarousel is still shows up for 1 second.why is this happening and how to stop this.I have used storyboard to create a iCarosel view..
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [idOfAllWords count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 250.0f)];
((UIImageView *)view).image = [UIImage imageNamed:#"page.png"];
view.contentMode = UIViewContentModeCenter;
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
}
else
{
label = (UILabel *)[view viewWithTag:1];
}
Words *word=nil;
word=idOfAllWords[index];
label.text =word.Name;
return view;
}
Hiding and unhiding is not the solution. What you need is just one line:
yourCarousel.clipsToBounds = YES;
I actually tried to reproduce your problem and did see that the carousel view stays for a second when 'pop' or back button press happens. This particularly happens when you the carousel is swiped and then the back button pressed. As a workaround, I was able to fix it by setting the iCarousel hidden in the viewWillDisappear method.
- (void)viewWillDisappear:(BOOL)animated
{
[YOUR_CAROUSEL_NAME setHidden:YES]; //This sets the carousel to be hidden when you press Back button
}
If this looks to be hidden suddenly, you can perhaps try setting the alpha to 0.0 inside an animation block. Something like this:
- (void)viewWillDisappear:(BOOL)animated
{
//[YOUR_CAROUSEL_NAME setHidden:YES];
[UIView animateWithDuration:0.2f animations:^{
[YOUR_CAROUSEL_NAME setAlpha:0.0f]; //This makes the carousel hide smoothly
}];
}
Hope this helps!
I'm a newbie when it comes to building apps. Is there any way to make an image appear when a button is pressed? I already have the button displaying text on a label when pushed. Here is my code for the button:
- (IBAction)ClickMe:(id)sender
{
_resultLabel.text = self.tempText.text;
}
Just load the image into a uiimageview. Set it hidden at the start. When you press the button, unhide, if pressed again hide (toggle)
Try this
imageView.hidden = NO;
first create an imageView and assign an image to it .
#interface UIImageViewCustom : UIViewController {
UIImageView *imageView ;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* image = [UIImage imageNamed:#"abc.jpeg"];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(40,40,200,100)];
imageView.backgroundColor = [UIColor blackColor];
imageView.clipsToBounds = YES;
imageView.image = image;
}
and then add it to view when button is pressed .
- (IBAction)ClickMe:(id)sender
{
_resultLabel.text = self.tempText.text;
[self.view addSubView:imageView];
}