Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-30-2009, 04:06 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default Determining UIButton "touch-up inside" Duration + UIImageView

Hello, I got one pressing issue which can prevent my app from ever happening. I have a button which on "touch up inside" starts a UIImageView animation.

What I'd like to have happen is create a custom handler for that button which detects how long the user kept the button pressed and play a different UIImageView animation while that is happening (it can happen on the same UIImageView or on a superimposed one, after making the "background UIImageView" invisible). Ideally, upon button release I'd like to get back to the original animation.

Any ideas and suggestions are appreciated - lemme know what you guys think.
blackoutq3 is offline   Reply With Quote
Old 11-30-2009, 04:10 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 519
Default

Instead of using an IBAction touch, you can use a touchesBegan and touchesEnded event.

This will allow you to detect the time they held their touch down inside the button.
__________________
Water Your Body (ON SALE $0.99)

Top Paid in Health & Fitness!

Tic Tac Pro ($0.99)

New and Noteworthy!

Click here to see a really cool website
bravetarget is offline   Reply With Quote
Old 11-30-2009, 04:55 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

Quote:
Originally Posted by bravetarget View Post
Instead of using an IBAction touch, you can use a touchesBegan and touchesEnded event.

This will allow you to detect the time they held their touch down inside the button.
Right, but using a timer is out of the question because the animation doesn't happen after the user releases the button, but while the button is pressed.
blackoutq3 is offline   Reply With Quote
Old 11-30-2009, 05:03 PM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 519
Default

Quote:
Originally Posted by blackoutq3 View Post
Right, but using a timer is out of the question because the animation doesn't happen after the user releases the button, but while the button is pressed.
In that case, touchesBegan would set the animation to start in an infinite loop.

touchesEnded would set the animation to stop.
__________________
Water Your Body (ON SALE $0.99)

Top Paid in Health & Fitness!

Tic Tac Pro ($0.99)

New and Noteworthy!

Click here to see a really cool website
bravetarget is offline   Reply With Quote
Old 11-30-2009, 05:06 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

I'll try that, bravetarget

EDIT: sorry for the double post, my connection is buggy
blackoutq3 is offline   Reply With Quote
Old 12-01-2009, 12:13 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

So apparently touchesBegan only picks up touches on the UIImageView and ignores touches on the button below it.

Any other suggestions? I really need to solve this.
blackoutq3 is offline   Reply With Quote
Old 12-01-2009, 12:17 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

subclass UIButton
dancriel is offline   Reply With Quote
Old 12-01-2009, 02:34 PM   #8 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

Is this what you meant by subclassing the button? Provided this code is right, how can I add the touchesBegan as the @selector for this button?

Once again, I really appreciate the help.
Code:
        button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	
	//set the position of the button
	button1.frame = CGRectMake(5, 5, 60, 60);
	
	//set the button's title
	[button1 setTitle:@"title" 
			 forState:UIControlStateNormal];
	
	//listen for clicks
	[button1 addTarget:self 
				action:@selector(changeMainView:) // change this function
	  forControlEvents:UIControlEventTouchUpInside];
	
	//add the button to the view
	[self.view addSubview:button1];

Last edited by blackoutq3; 12-01-2009 at 02:37 PM.
blackoutq3 is offline   Reply With Quote
Old 12-01-2009, 02:36 PM   #9 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

subclass UIButton.
dancriel is offline   Reply With Quote
Old 12-01-2009, 03:46 PM   #10 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

Repeating your answer (period and all ) doesn't do too much good. I clearly am a beginner who needs help. What do you mean by subclassing a UIButton? Have it sit in its own class? (seems pointless)

Last edited by blackoutq3; 12-01-2009 at 03:49 PM.
blackoutq3 is offline   Reply With Quote
Old 12-01-2009, 03:56 PM   #11 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

"subclassing" means defining your own subclass of an NSObject which takes on all the behavior of the object (UIButton, in this case) plus whatever funcionality you add/override.

in this case i'm suggesting you create your own subclass of UIButton which will allow you to override the touch methods (touchesBegan, touchesMoved, etc) of the button. then you can calculate the time between touchesBegan and touchesEnded. you can then pass this info to the button's delegate (your view controller).

this might be too advanced if you're totally new to this, so if words like "subclass" and "delegate" make you go WTF MAN then you should start with an objective-c primer. the Stanford iPhone development course (available for free on iTunes U right) is a great resource for a beginner to get familiar with Obj-C and Cocoa Touch.
dancriel is offline   Reply With Quote
Old 12-01-2009, 03:57 PM   #12 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

btw your response to bravetarget seems to indicate you don't understand how touches are handled and passed to views on the iPhone. no offense, but you should probably RTFM a little.
dancriel is offline   Reply With Quote
Old 12-01-2009, 04:35 PM   #13 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

one last thought, look into the different UIControlEvents available to you. TouchUpInside is only one of many events that exist for a UIButton. There is probably an event that fires as soon as the finger touches the button, and another that fires when the finger is lifted. define a "buttonTouched" and a "buttonReleased" method, assign them to the appropriate button events, and...see where i'm going with that?

sometimes i forget that i was once a n00b myself.
dancriel is offline   Reply With Quote
Old 12-01-2009, 05:26 PM   #14 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
Default

The whole MVC model makes sense to me. I just didn't know that defining your custom object which inherits UIButton is called "subclassing". Noted.

PS: I was taught C and C++ in Romanian, so I have a few issues with nomenclature still.

Thanks a bunch dancriel, this forum never seems to disappoint.
blackoutq3 is offline   Reply With Quote
Old 12-01-2009, 06:26 PM   #15 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

cool man let us know if you get it working.
dancriel is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, custom event, duration, uibutton, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 280
20 members and 260 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0