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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-09-2010, 05:14 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Portugal
Posts: 20
sapateira is on a distinguished road
Question How to scale with single touch?

Hi guys. I've been searching a lot for this but i only find tutorials on how to scale an image using multitouch (2 fingers to scale, drag, rotate, etc.)

Lets say i have a barchart. How can i adujust bar value (size) with just one finger, by draging the bar or by just pointing to the new value in the chart?

This is my idea on how this could be done:

Each bar is an image that in it's full size represents the 100% value in the chart. Then by draging my finger it would scale the image from 100% to 0%.

It can only scale in one direction Y or X (deponding on chart orientation), and the scale must have a basepoint (anchor point) so that one side of the bar is always at the chart base value of 0%.

Can anyone point me some code?

Last edited by sapateira; 11-15-2010 at 09:43 AM.
sapateira is offline   Reply With Quote
Old 11-09-2010, 06:43 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Portugal
Posts: 20
sapateira is on a distinguished road
Lightbulb Set anchor point

Already figured out how to set an anchor point so the image doesn't resize from the center:

Code:
imageView.layer.anchorPoint = CGPointMake(0,0);
sapateira is offline   Reply With Quote
Old 11-15-2010, 04:15 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Portugal
Posts: 20
sapateira is on a distinguished road
Red face Create an interactive Bar Chart

Since no one helped, I'll be doing things a different way.

I'll be drawing the chart from UITextField keyboard inputs.
This is lame. I Would love to take advantage of the touch interface here. Anyway, i hope this helps someone.

Made this action and linked it to a button in the view. Once pressed it reads the value entered in the UITexField and scales the bar of the chart to that value.

Input01 is my UITextField where i input the desired value for Bar01
Bar01 is an UIImageView and is the 1st bar from my chart

Code:
@synthesize Bar01;
@synthesize Input01;

- (IBAction)PushGo{
		
	float Val01;
	Val01 = [Input01.text floatValue];
	
	// move anchor point without moving frame
	CGRect oldFrame = Bar01.frame;
	Bar01.layer.anchorPoint = CGPointMake(0, 0);  //bottom left is new anchor point
	Bar01.frame = oldFrame;
	
	if ([Input01.text length] > 0){
		
		if ((Val01 < 0) || (Val01 > 100)) {
			//alert that input isn't accepted
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Alert"
                                                                        message: @"Only numbers from 0 to 100"
                                                                       delegate: self
                                                              cancelButtonTitle: @"Close"
                                                              otherButtonTitles: nil];
			[alert show];
			[alert release];
                        //clear UITextfield
			Input01.text = nil;
		}
		if ((Val01 > 0) && (Val01 <= 100)){	
			
			[UIView beginAnimations:nil context:NULL];
			[UIView setAnimationDuration:2];
			Bar01.transform = CGAffineTransformMakeScale(1, Val01);
			[UIView commitAnimations];
		}
		
		if (Val01 == 0) {
			
			[UIView beginAnimations:nil context:NULL];
	                [UIView setAnimationDuration:0.5];
	                Bar01.transform = CGAffineTransformIdentity;
	                [UIView commitAnimations];
		}			
	}
}

- (void)dealloc {
	
	[Bar01 dealloc];
	[Bar01 release];
	[Input01 dealloc];
	[Input01 release];
        [super dealloc];
	[super release];
	
}

Last edited by sapateira; 11-15-2010 at 06:17 AM.
sapateira is offline   Reply With Quote
Old 11-15-2010, 06:30 AM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Why not use a slider to set the bar value instead of inputing it in a text field?
baja_yu is offline   Reply With Quote
Old 11-15-2010, 08:59 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Portugal
Posts: 20
sapateira is on a distinguished road
Post That gives me an idea

Your post gave me an idea that can almost do the trick:

Put a slider on top of a bar.
Match the slider size to 100% of the bar value.
Link the slider value to the scale factor applied to the bar.
Set the slider invisible and hurray.

Well, not quite!!!

1st problem: Can't set the slider completely invisible. If alpha value is lower then 0.02 the slider stops working, as if it isn't even there.

2nd problem: AnchorPoint no longer works correctly and the scale goes nuts. I'm using the following code to set the new anchor point.
Code:
CGRect oldFrame = Bar01.frame;
Bar01.layer.anchorPoint = CGPointMake(0, 0.5);
Bar01.frame = oldFrame;
Any ideas?

Last edited by sapateira; 11-15-2010 at 09:04 AM.
sapateira is offline   Reply With Quote
Old 11-15-2010, 09:04 AM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

This isn't exactly what you were going for but it might work. Instead of changing bar values by dragging the bars directly, implement some sort of selection. Let's say you have five bars, tap one to select it and a toolbar with a slider on it appears (slides) into view which you can move to set the bar level.

Sorry that I can't give you a more concrete help but only ideas. I'm rather new to iOS development and didn't do much with graphics programming.
baja_yu is offline   Reply With Quote
Old 11-15-2010, 01:09 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Portugal
Posts: 20
sapateira is on a distinguished road
Thumbs up Work complete

It's done. Not the right way, but the tricky way!
Thanx baja_yu you pointed me in the "right" direction.

1. The problem with the anchorPoint is that is has to be set in the viewDidLoad and not in the IBAction that sets the scale.

Code:
@synthesize Bar01, Slider01;

- (void) viewDidLoad {

	//Draws bar

	Bar01 = [[UIImageView alloc] initWithFrame: CGRectMake (111, 153, 1, 30)];
	[Bar01 setImage:[UIImage imageNamed:@"image.png"]];
	[self.view addSubview:Bar01];

	//Sets anchorPoint

	CGRect oldFrame01 = Bar01.frame;
	Bar01.layer.anchorPoint = CGPointMake(0, 0);
	Bar01.frame = oldFrame01;
	
	[super viewDidLoad];

}

//apply scale factor from slider to the bar

- (IBAction)SlideToScaleBar01: (id) Slider01 {

	float SliderValue01 = Slider01.value;
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:0];
	Bar01.transform = CGAffineTransformMakeScale(SliderValue01, 1);
	[UIView commitAnimations];

}

- (void)dealloc {
	
	[Bar01 dealloc];
	[Bar01 release];
	[Slider01 dealloc];
	[Slider01 release];
        [super dealloc];
	[super release];
	
}
2. The slider set in top of the bar with alpha = 0.02 isn't noticeable.
sapateira is offline   Reply With Quote
Reply

Bookmarks

Tags
bar, chart, drag, image, scale

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: 344
10 members and 334 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, Paul Slocum
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

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