UIButton under hidden UILabel won't work - iphone

I have a large UILabel which I am using to cover a bunch of buttons while I do something else.
All I have set initially is myLabel.hidden = YES; so you can't see the UILabel but the UIButtons (below it) won't work anymore.
Is there another setting for the UILabel I can use to allow touches to go "through it" when it is hidden? Thanks.

why use a UILabel to cover your buttons.
just set
UIButton *button;
[button setUserInteractionEnabled:NO];
or
[button setUserInteractionEnabled:YES];

You can use addSubView and removeFromSuperview methods :
When you want to hide your UIButton with your UILabel :
[self.view addSubview:myLabel];
and the contrary :
[myLabel removeFromSuperview];

I am not sure why a hide is stopping the touch events on buttons. Anyways you can explicitly bring the buttons to foreground by the following calls.
[self bringSubviewToFront:button];

The simplest thing to use as a general way to hide or cover things just a straight UIView. set:
[myCoverView setUserInteractionEnabled:YES];
and it will intercept touches and block touches to the buttons below it.
It should stop blocking touches when you hide it or turn the alpha to 0.0;
You can always siwtch the covering views interaction to:
[myCoverView setUserInteractionEnabled:NO];
and touches will pass through it.
If there is some reason that you need the UILabel these methods will work with it also.

[myLabel setUserInteractionEnabled:NO].
Even if is hidden, your label will get the touches anyway. You have to disable that to achieve what u want.

I think you should hide your buttons instead of covering them with a label.
[yourButton setHidden = YES];
[yourButton2 setHidden = YES];
...

Related

How to implement the smash effect in uibutton

I am using uibutton to smack that to interact it like fruit ninja ,i don't want to cut it , just interact the uibutton to smack it,how to implement that help me how to do that.
Instead of UIButton use a UIImageView and set it's userInteractionEnable property to true.
Add a swipe gesture to that imageView, It will solve your problem.
The control used is swipe gesture on the view ,Not the uibutton with button click event.
A nice tutorial
You can use the UISwipeGestureRecognizer for this.
UISwipeGestureRecognizer *mSwipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(doSomething)];
[mSwipeUpRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:mSwipeUpRecognizer];
[mSwipeUpRecognizer release];
And in your .h file, add the delegate:
<UIGestureRecognizerDelegate>

is it possible to disable keyboad(UITextField) without hidding?

I'd like to disable UITextField's keyboard without hidding.
is it possible?
If it's so, could you show me how to do?
thanx
Carsh
if you implement delegate method of uitextfield
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
It does not show the keyboard.
I don't believe the UIKeyboard can be disabled without hiding it.
If you'd like to disable user interaction with the keyboard, you could add an extra UIWindow on top of your existing windows.
By overlaying the UIKeyboard with a transparent UIWindow, the user would be able to see the keyboard, without interacting with it.
a haha , i have a very very ugly method. you can creat a view whichs frame = the keyboards frame. [view setBackgroundColor:[UIColor clearColor]]; [self addSubviews:view];
I did not try but this should work:
textField.inputView.userInteractionEnabled = NO;

Touch Event on image , achieved by using UIButton but show up delayed compare to UIImageView

Sorry for the messy title, I just don't know how to describe the problem in a delicate way.
I'm writing a album-like app to display a bunch of image in my scrollview and do something when a image is touched.
I followed this question : how can i detect the touch event of an UIImageView and use button with background image to handle touch event.
My original method is using NSOperation to concurrently fetch image from internet and put it io a imageview and add to my scrollview, and the speed is quite ok because each imageview shows right after each NSOperation callback.
Then I change imageview to uibutton, the strange thing is that when a NSOperation callback, that button does not show in my view. They show up at once when all the NSOperation callback is done. That makes the user experience become unacceptable.
This is my NSOperation callback function, it will pass a button that contains the image fetched from internet
- (void)imageLoaded:(UIButton*)button;
{
NSLog(#"Done");
[button addTarget:self action:#selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
The buttons will only displa after the last "Done" appear instead of one by one, is that normal? or I messed up something?
==== update ========
I think I'm running the NSOperation on my viewcontroller. I have a imageLoadOperation class, I'll pass my viewcontroller to it
imageLoadOperation *ilo = [[imageLoadOperation alloc] initWithURLString:[NSString stringWithFormat:#"link for the image"];
[ilo setParent:self];
[queue addOperation:ilo];
[ilo release];
And in the main function of imageLoadOperation I'll do
[parentViewController performSelectorOnMainThread:#selector(imageLoaded:) withObject:button waitUntilDone:NO];
Do you mean I need to move these code to my AppDelegate instead of running in my viewcontrollor?
You can use a button of custom type over your image view instead of using button with background image, or you can use touch event on an UIImageView
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
What if instead of converting to a button you just allowed your UIImageView to handle the touch event?
To add a touch event to a UIImageView use the following format in your .m
UITapGestureRecognizer *newTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(newTapMethod)];
[_imageButtonName setUserInteractionEnabled:YES];
[_imageButtonName addGestureRecognizer:newTap];
then create the newTapMethod (or what ever you name it)
-(void)newTapMethod{
//...
}
hope that helps.

How to add a HUD? (iOS)

I am trying to have some controls appear when you push a button and have it disappear when you press a different button. Right now the HUD is comprised of an image view, and some custom buttons in a UIView called "credits". I've managed to have it disappear using:
[credits removeFromSuperview];
How do I have it reappear?
If it's just a UIImageView, you should...
[self.view addSubview:credits];
... assuming you've not released it already. On a side note, there is a really good HUD for iOS here: http://github.com/matej/MBProgressHUD
I believe you can just set the view to be hidden
[self.view setHidden:YES];
While it's hidden, you can also update the view and then show again
[self.view setHidden:NO];
You'd better set their hidden property to whether YES or NO
This method will toggle the UIView credits hidden property
- (void) toggleCredits {
[credits setHidden:![credits isHidden]];
}

Two Problems I'm having with UIButton and UIView

I haven't been programming on the iPhone for very long, but I'm picking it up slowly by googling problems I get. Unfortunately I haven't been able to find an answer for these.
I have started a new View-based application in Xcode 3.2.2 and immediately added the following files: myUIView.m and myUIView.h, which are subclasses of UIView. In Interface Builder, I set the subclass of the default UIView to be myUIView.
I made a button in the drawRect method.
Problem one: The title of the button only appears AFTER I click the screen, why?
Problem two: I want the button to produce the modalview - is this possible?
The code is as follow:
#import "myUIView.h"
#implementation myUIView
- (void)drawRect:(CGRect)rect {
// Drawing code
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,100,100);
[button setTitle:#"butty" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
-(void)buttonPressed:(id)sender{
NSLog(#"Button pressed");
//present modal view somehow..?
}
I can't see how to post attachments, but if anyone thinks it will help I can upload the source.
Many thanks,
Andy
drawRect: is for custom drawing. You won't often need to do that. Your button won't be drawn until it gets sent drawRect:, probably in the next iteration of the run loop (ie, when you click on the view).
If you want a button on your view, either drag it there using IB, or move the code from drawRect: to viewDidLoad.
You present a modal view from a view controller by:
[self presentModalViewController:viewController animated:YES];
Do this in the action method your button sends to your view controller. This should indicate to you that you need to take a look at your application design.