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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2009, 01:23 PM   #26 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 5
mtodag is on a distinguished road
Default

Great Tutorial=)I want the degree of the 3 values X,Y and Z for example showing on a label.....Can anybody help me??
mtodag is offline   Reply With Quote
Old 04-18-2009, 12:02 AM   #27 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Quote:
Originally Posted by netsmith View Post
Is this missing from the code at the top?

Sorry another Newb here - could the original post be updated if it is.

I'm getting this error
2009-04-17 15:37:26.599 accel[1328:107] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "accelViewController" nib but the view outlet was not set.'


Cheers
Chris
Go into the nib file and make sure that the view outlet is set on the nib (open inspector and click once on "view" in the window. then see if there's a black dot under referencing outlet)
meowmix23F is offline   Reply With Quote
Old 04-19-2009, 07:03 PM   #28 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Quote:
Originally Posted by mtodag View Post
Great Tutorial=)I want the degree of the 3 values X,Y and Z for example showing on a label.....Can anybody help me??
Just call (this assumes that your label is called "mylabel", and the variable for the 'x' value is called x

[mylabel setText:[NSString stringWithFormat:@"%d",x]];
meowmix23F is offline   Reply With Quote
Old 04-20-2009, 02:27 AM   #29 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 23
netsmith is on a distinguished road
Default

Quote:
Originally Posted by meowmix23F View Post
Go into the nib file and make sure that the view outlet is set on the nib (open inspector and click once on "view" in the window. then see if there's a black dot under referencing outlet)
Thanks for getting back to me - is that the NIB for the main window or the view controller?

Thanks
Chris
netsmith is offline   Reply With Quote
Old 04-20-2009, 06:14 AM   #30 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Quote:
Originally Posted by netsmith View Post
Thanks for getting back to me - is that the NIB for the main window or the view controller?

Thanks
Chris
The ViewController nib...

And can we please stop double posting (@deviphone)? Thanks.
meowmix23F is offline   Reply With Quote
Old 04-20-2009, 04:55 PM   #31 (permalink)
Top Contributor
 
Join Date: Apr 2009
Location: N/A
Posts: 478
williamlegate is on a distinguished road
Default

Quote:
Originally Posted by netsmith View Post
Is this missing from the code at the top?

Sorry another Newb here - could the original post be updated if it is.

I'm getting this error
2009-04-17 15:37:26.599 accel[1328:107] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "accelViewController" nib but the view outlet was not set.'


Cheers
Chris
RESPOND TO MY EMAILS!!!
williamlegate is offline   Reply With Quote
Old 04-20-2009, 05:02 PM   #32 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Quote:
Originally Posted by williamlegate View Post
RESPOND TO MY EMAILS!!!
I did, and please stop flooding my tutorial thread. kthx
meowmix23F is offline   Reply With Quote
Old 05-07-2009, 05:15 AM   #33 (permalink)
New Member
 
Join Date: Mar 2009
Location: Calgary, Alberta, Canada
Posts: 24
speasley is on a distinguished road
Default

Hello,

I'm getting this error:

Code:
*** -[NSCFType accelerometer:didAccelerate:]: unrecognized selector sent to instance 0x135470
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType accelerometer:didAccelerate:]: unrecognized selector sent to instance 0x135470'
from:

Code:
- (void)accelerometer:(UIAccelerometer *)accel didAccelerate:(UIAcceleration *)aceler { 
//empty for now
}
Does that mean that 'aceler' needs to be defined somewhere else first?

Sometimes, instead of the above, I get the error:

Code:
Program received signal:  “EXC_BAD_ACCESS”.
And interestingly, if I comment out all the UIAccelerometer code, and shake the phone... the app hangs with nothing spit out to the console or debugger. Everything still shows "GDB: Running..."

Thanks.

Last edited by speasley; 05-07-2009 at 05:53 AM.
speasley is offline   Reply With Quote
Old 05-09-2009, 09:57 AM   #34 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

hmm, that's weird. I'm going to post source code for the tutorial very soon, anyway.
meowmix23F is offline   Reply With Quote
Old 05-17-2009, 12:05 PM   #35 (permalink)
New Member
 
Join Date: May 2009
Posts: 3
thevieweast is on a distinguished road
Default could you please ?

Quote:
Originally Posted by meowmix23F View Post
hmm, that's weird. I'm going to post source code for the tutorial very soon, anyway.
if you wouldn't mind, i'd love to see a .xcodeproj of this file.

thanks in advance
thevieweast is offline   Reply With Quote
Old 07-25-2009, 11:39 PM   #36 (permalink)
Tutorial Author
 
Join Date: Jul 2009
Posts: 49
MaXiMuM is on a distinguished road
Default

To fix change the line
Code:
@property (nonatomic, retain) IBOutlet UIlabel *label;
To
Code:
@property (nonatomic, retain) IBOutlet UILabel *label;
He forgot to capitalize the L in UILabel

Quote:
Originally Posted by speasley View Post
Total newb here... but I hit a wall here:



The only outlet option I have here is for "view".

I've just fallen off the iPhone turnip truck, so bear with me. Thanks.
MaXiMuM is offline   Reply With Quote
Old 07-25-2009, 11:41 PM   #37 (permalink)
Tutorial Author
 
Join Date: Jul 2009
Posts: 49
MaXiMuM is on a distinguished road
Default

For those who are having trouble connecting the label in IB
Follow my Above Post

To fix change the line

Code:
@property (nonatomic, retain) IBOutlet UIlabel *label;
To
Code:
@property (nonatomic, retain) IBOutlet UILabel *label;
MaXiMuM is offline   Reply With Quote
Old 08-04-2009, 04:34 AM   #38 (permalink)
New Member
 
Join Date: Aug 2009
Posts: 2
hydromike2 is on a distinguished road
Default small typo

Code:
[label setText:@"fixed"]
should have been
Code:
[label setText:@"fixed"];
it was missing the semi colon and i was overlooking it for a while, but in any case thanks for the super easy tutorial!
hydromike2 is offline   Reply With Quote
Old 09-09-2009, 06:17 AM   #39 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 28
ravalashish82 is on a distinguished road
Default Help me to move object without touch

Quote:
Originally Posted by Alx View Post
Thanks for this tutorial.

I'm fighting with this Accelerometer since some days now.

I'm trying to move an object on the iphone's screen, by using the accelerometer.

When the iphone is flat, it's working fine.
Else, it's completely wrong.

I've to calibrate the iPhone.
But I can't understand how to do this.
Would someone please help me?

I'm running the app' in landscape mode.

Here is how I get the accelerometer values:

Code:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

    accelerometerValues[0] = acceleration.x * kFilteringFactor + accelerometerValues[0] * (1.0 - kFilteringFactor);
	accelerometerValues[1] = acceleration.y * kFilteringFactor + accelerometerValues[1] * (1.0 - kFilteringFactor);
	accelerometerValues[2] = acceleration.z * kFilteringFactor + accelerometerValues[2] * (1.0 - kFilteringFactor);
}
Here is how I compute the new position of my object:
Code:
- (void) tick
{
	if (gameFinished)
		return;
	
	float                dTime;
    CFTimeInterval        time;
	
    time = CFAbsoluteTimeGetCurrent();
    dTime = time - lastTime;
	
	float accelerationX = (accelerometerValues[1]) * dTime * 1000;
    float accelerationY = (accelerometerValues[0]) * dTime * 1000;
	
	float newX=m_TargetImgView.center.x+accelerationX;
	float newY=m_TargetImgView.center.y+accelerationY;
	
	if (newX < 0)
		newX=0;
	else if (newX > 480)
		newX = 480;
	
	if (newY < 0)
		newY=0;
	else if (newY > 320)
		newY = 320;
	
	m_myImgView.center=CGPointMake(newX,newY);
	
	lastTime = time;
}
Thanks in advance for any help

Alx

Hello Friend...

I want to tht I have one object in iphone when i move my iphone in right side then tht object is move in right side same as tht is working in left side also

i'm doing some experiment ... but i'm fail...


- (void)accelerometerUIAccelerometer *)accelerometer didAccelerateUIAcceleration *)acceleration {
// Get the current device angle
float xx = -[acceleration x];
float yy = [acceleration y];


// Read my blog for more details on the angles. It should be obvious that you
// could fire a custom shouldAutorotateToInterfaceOrientation-event here.

float angle = atan2(yy, xx);

// Add 1.5 to the angle to keep the label constantly horizontal to the viewer.
[myImage setTransform:CGAffineTransformMakeRotation(angle+1 .5)];

// if(y > 0.3) //Left
// {
// myImage.frame = myImage.frame.origin.x - 2, myImage.frame.origin.y;
// //playertank.position = cpv(playertank.position.x - 2, playertank.position.y);
// }
// else if(y < -0.3) //Right
// {
// playertank.position = cpv(playertank.position.x + 2, playertank.position.y);
// }
// else if(x > -0.3)//up
// {
// playertank.position = cpv(playertank.position.x, playertank.position.y + 2);
// }
// else if(x < -0.7)//Down
// {
// playertank.position = cpv(playertank.position.x , playertank.position.y - 2);
// }
//}
//
if(angle >= -2.25 && angle <= -0.25)
{
if(deviceOrientation != UIInterfaceOrientationPortrait)
{
deviceOrientation = UIInterfaceOrientationPortrait;

//[button1 setText:@"UIInterfaceOrientationPortrait"];
}
}
else if(angle >= -1.75 && angle <= 0.75)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeRight)
{
deviceOrientation = UIInterfaceOrientationLandscapeRight;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationLandscapeRight"];
}
}
else if(angle >= 0.75 && angle <= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
{
deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationPortraitUpsideDown"];
}
}
else if(angle <= -2.25 || angle >= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeLeft)
{
deviceOrientation = UIInterfaceOrientationLandscapeLeft;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationLandscapeLeft"];
}
}

}

so plz help me friend it's urgent....
ravalashish82 is offline   Reply With Quote
Old 09-09-2009, 06:18 AM   #40 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 28
ravalashish82 is on a distinguished road
Default

Quote:
Originally Posted by meowmix23F View Post
hmm, that's weird. I'm going to post source code for the tutorial very soon, anyway.
Hello Friend...

I want to tht I have one object in iphone when i move my iphone in right side then tht object is move in right side same as tht is working in left side also

i'm doing some experiment ... but i'm fail...


- (void)accelerometerUIAccelerometer *)accelerometer didAccelerateUIAcceleration *)acceleration {
// Get the current device angle
float xx = -[acceleration x];
float yy = [acceleration y];


// Read my blog for more details on the angles. It should be obvious that you
// could fire a custom shouldAutorotateToInterfaceOrientation-event here.

float angle = atan2(yy, xx);

// Add 1.5 to the angle to keep the label constantly horizontal to the viewer.
[myImage setTransform:CGAffineTransformMakeRotation(angle+1 .5)];

// if(y > 0.3) //Left
// {
// myImage.frame = myImage.frame.origin.x - 2, myImage.frame.origin.y;
// //playertank.position = cpv(playertank.position.x - 2, playertank.position.y);
// }
// else if(y < -0.3) //Right
// {
// playertank.position = cpv(playertank.position.x + 2, playertank.position.y);
// }
// else if(x > -0.3)//up
// {
// playertank.position = cpv(playertank.position.x, playertank.position.y + 2);
// }
// else if(x < -0.7)//Down
// {
// playertank.position = cpv(playertank.position.x , playertank.position.y - 2);
// }
//}
//
if(angle >= -2.25 && angle <= -0.25)
{
if(deviceOrientation != UIInterfaceOrientationPortrait)
{
deviceOrientation = UIInterfaceOrientationPortrait;

//[button1 setText:@"UIInterfaceOrientationPortrait"];
}
}
else if(angle >= -1.75 && angle <= 0.75)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeRight)
{
deviceOrientation = UIInterfaceOrientationLandscapeRight;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationLandscapeRight"];
}
}
else if(angle >= 0.75 && angle <= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
{
deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationPortraitUpsideDown"];
}
}
else if(angle <= -2.25 || angle >= 2.25)
{
if(deviceOrientation != UIInterfaceOrientationLandscapeLeft)
{
deviceOrientation = UIInterfaceOrientationLandscapeLeft;
//[interfaceOrientationLabel setText:@"UIInterfaceOrientationLandscapeLeft"];
}
}

}

so plz help me friend it's urgent....
ravalashish82 is offline   Reply With Quote
Old 10-01-2009, 07:23 PM   #41 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 28
glossywhite is on a distinguished road
Default

Your initial post IS SEVERELY FLAWED!!!. Can you just post the .h and .m source, please?
glossywhite is offline   Reply With Quote
Old 10-08-2009, 03:47 PM   #42 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 361
pofak is on a distinguished road
Default

Is didAccelerate called over and over if the user keeps shaking the device without stopping? If yes, how it can be detected that this is the same shake?
pofak is offline   Reply With Quote
Old 01-22-2010, 06:19 AM   #43 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 4
kalpan is on a distinguished road
Post Need same kind help

HI.

I have a requirement to move object (image) in particular direction using Accelerometer.

I am facing same kind of problem. I could not determine direction. please help.
kalpan is offline   Reply With Quote
Old 09-18-2010, 07:02 AM   #44 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 2
ganeshiiphone is on a distinguished road
Smile I have a doubt

Thank you for posting such a helpful tutorial, it has cleared all my doubts except the following....

- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation

is calling when ever shake the iPhone.

it should not call in my Application...

then what should i do?

Thanks in advance for your reply.
ganeshiiphone is offline   Reply With Quote
Old 10-06-2010, 05:13 AM   #45 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 54
pinu is on a distinguished road
Default

Quote:
Originally Posted by netsmith View Post
Is this missing from the code at the top?

Sorry another Newb here - could the original post be updated if it is.

I'm getting this error
2009-04-17 15:37:26.599 accel[1328:107] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "accelViewController" nib but the view outlet was not set.'


Cheers
Chris
Hi meowmix23F,
I m new to this iphone world,n doing a task for moving object on camera view,using accelerometer,its moving when axis are getting changed,but i want it to move even if we just move the camera...that time axis doesn't get changed,so then object...do u have a solution for this??
pinu is offline   Reply With Quote
Old 11-28-2010, 03:00 PM   #46 (permalink)
KKK
Registered Member
 
Join Date: Nov 2010
Posts: 2
KKK is on a distinguished road
Default HELP ME PLZ

How to connect sound with the accelerometer shake? i want to insert some music files to my app, but dont have an idea how to relate sound and accelerometer....
KKK is offline   Reply With Quote
Old 11-30-2010, 11:56 PM   #47 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
meowmix23F is on a distinguished road
Default

Hey Guys,

I haven't been on this forum in a while, but don't worry, i'll answer all of your questions A.S.A.P
meowmix23F is offline   Reply With Quote
Old 03-24-2011, 11:54 AM   #48 (permalink)
Registered Member
 
Join Date: Sep 2010
Location: Berlin
Posts: 3
Helena158 is on a distinguished road
Default

Quote:
Originally Posted by meowmix23F View Post
Hey Guys,

I haven't been on this forum in a while, but don't worry, i'll answer all of your questions A.S.A.P
And you did not answer the questions
Helena158 is offline   Reply With Quote
Old 05-12-2011, 01:49 AM   #49 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 7
rajanallathambi is on a distinguished road
Thumbs up

Great Tutorial
rajanallathambi is offline   Reply With Quote
Old 05-30-2011, 06:31 AM   #50 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 8
venkat1282 is on a distinguished road
Default How to find out the X,Y,Z axis values of Iphone>

Hai,Iam new for this iphone applications.So please tell me how to find X,Y,Z axis values of iphone using uiaccelerometer.Please.
venkat1282 is offline   Reply With Quote
Reply

Bookmarks

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 472
18 members and 454 guests
7twenty7, alexeir, David-T, Dj_kades, Elad, foslock, HemiMG, iAppDeveloper, jeroenkeij, LunarMoon, Mijator, Pauluz85, pipposanta, QuantumDoja, robsmy, sacha1996, smithdale87, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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