iPhone sdk Tool Tip - iphone

Can i show a Tool tip like this:
Also, I want to show this tool tip when that area is pressed and HOLD. Is there a handler for this gesture?

You can do that in didSelectRowAtIndex method of TableViewController delegate method.
Look here. It is best implementation to have Popover controllers in iPhone. Download run and integrate into your code and change according to your requirement.

In addition to what #jennis said, there is indeed a way to capture long hold gestures you could use UILongPressGestureRecognizer
like this
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longHold)];
[cell addGestureRecognizer:gesture];
and longHold method
- (void) longHold
{
//Cell has recieved gesture
}

It works, I agree with Omar Abdelhafith
-(void)viewWillAppear:(BOOL)animated
{ //gesture declared in .h file
gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longHold)];
[your view addGestureRecognizer:gesture];
}
-(void)longHlod
{
//do whatever you want
}

Related

UILongPressGesture in iphone sdk

UILongPressGestureRecognizer *longPressOnUndoGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleLongPressOnUndoGesture:)];
[longPressOnUndoGesture setMinimumPressDuration:2.0];
[longPressOnUndoGesture release];
i have the above code to deasctivate the autoscroll timer in my applicationthis is the function for this.
-(void) handleLongPressOnUndoGesture:(UILongPressGestureRecognizer*)recognizer {
[autoscrollTimer invalidate];
}
but when i taptohold for 2 seconds it wont stop the timer.is there any error in my code for gesture.
Thanks in advance.
You're not using the gesture recognizer, as you release it immediately as you created it. You have to attach it to a view like this:
UILongPressGestureRecognizer *longPressOnUndoGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleLongPressOnUndoGesture:)];
[longPressOnUndoGesture setMinimumPressDuration:2.0];
// TRICK HERE
[self.view addGestureRecognizer:longPressUndoGesture];
[longPressOnUndoGesture release];
It seems to me that you are not adding the gesture recognizer to the view it should work upon:
[self.view addGestureRecognizer: longPressOnUndoGesture];
(if self is your controller).

How to get touch/click on a MPMoviePlayerController view when MPMovieControlStyle = MPMovieControlStyleNone

In one of my application, I don't want to show any video controllers. But I need to get the touch on the media player view. I need to do some other action on touch on the movie player. How can I implement that. Please help
Thanks in advance.
You can always attach a UITapGestureRecognizer to the view and handle the taps.
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[moviePlayer.view addGestureRecognizer:tap];
[tap release];
And handle the tap in handleTap:
- (void)handleTap:(UITapGestureRecognizer *)gesture {
// Do some other action as intended.
}
Of course this works only on iOS 3.2 and later.
You can also use this delegate method of UIGestureRecognizer.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

UITapGestureRecognizer not doing anything

I've got an app that displays a page of text with the ability to tap a button or swipe in a view to advance or retreat through various pages. The container view has two UISwipeGestureRecognizers attached, for swipe left and swipe right. No trouble with these gestures. But now I'm trying to add UITapGestureRecognizer to another view, providing an ability similar to iBooks or the Kindle app, tap the left to go back, the right to go forward. Nothing I do can get the gesture to fire. No hint that it is ever being triggered, even if I put the gesture on my topmost view and disable other gestures.
The view controller implements UIGestureRecognizerDelegate, though I've not needed to implement delegate methods. I did try implementing shouldReceiveTouch: without success.
Here's a snippet of code where I create and attach the gesture recognizer:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapGestureTurnPage:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
Try this on the view you're adding the gesture recognizers:
view.userInteractionEnabled = YES;
You mention that you've tried this, but just in case go through it again.
Try using the delegate with <UIGestureRecognizerDelegate> in the header and then setting the delegate:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapGestureTurnPage:)];
[self.view addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
Then implement this method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
return YES;
}
Then use a debugger or toss an NSLog into the above method and also tapGestureTurnPage: to see if these methods are being called.
Add this where you initialize the gesture:
recognizer.delegate = self;
and add this in the "self" class:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
This allows me to have gestures recognized on the UIWebView, and the UIWebView will still respond to the taps. (which i wanted - you may not)

Open a view on image Click in cover flow

I am using cover flow library in my project.My cover flow consist of many images.What I want to do is when I click on that image another View Controller should gets open.
Please tell me how to open another view on that image click.
Any help will be highly appreciated.
I had the same problem yesterday. I had to change something in the framework.
Add these two methods in the interface
#interface AFOpenFlowView : UIView
- (AFItemView *)selectedCoverView;
- (UIScrollView *)scrollView;
Add the implementations of these two methods inside of the .m file
#implementation AFOpenFlowView
- (AFItemView *)selectedCoverView {
return selectedCoverView;
}
- (UIScrollView *)scrollView {
return scrollView;
}
Set a UITapGestureRecognizer in the view controller where you're using the AFOpenFlowView
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(screenTapped:)];
[[self view] addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}
At the end implement the method to handle the tap on the screen
- (void)screenTapped:(UITapGestureRecognizer *)tap {
CGPoint point = [tap locationInView:[af scrollView]];
if (CGRectContainsPoint([[af selectedCoverView] frame], point)) {
// Write here the code to open your view
// Use [af selectedCoverView].number to get the index of the selected cover
NSLog(#"selected cover view: %d", [af selectedCoverView].number);
}
}
Hope it's going to save you some time! ;)
Please try other FlowCover this is very easy to use...
Thanks

is Gesture Recognization working on buttons or not?

In my app, I wrote these lines of code :
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
[mybutton1 addGestureRecognizer:tapper];
[mybutton2 addGestureRecognizer:tapper];
[mybutton3 addGestureRecognizer:tapper];
[tapper release];
}
-(void)tapped:(UIGestureRecognizer *)sender{
NSLog(#"I'am in tapped");
}
but nothing happened. why ? and if I need to get the button's currentTitle inside tapped, can I ?
Thanks
You're missing the recognizer delegate. Implement that. You should also add the UIGestureRecognizerDelegate protocol to your header file and make recognizer.delegate = self.
re: getting the title - you can get the title. in your tap event handler you can extract that information from the sender object. i'll post some code later...
You don't need to use a gesture recogniser just to detect when a button is pressed. A button knows when it's being pressed!
Try:
{
// Blah...
[myButton addTarget:self action:#selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
// Other stuff
}
-(void)tapped:(id)sender {
NSLog (#"I'm in tapped!");
}
A gesture recognizer can only be attached to one view at a time. Handling single taps on buttons can just as easily be done using IBAction. You can create one IBAction and connect all three buttons to it.
- (IBAction)tapped:(id)sender {
UIButton *button = (UIButton *)sender;
NSLog(#"%#", button.titleLabel.text);
}
A similar question: UITapGestureRecognizer on a UIButton