Move shapes drawen in context+iphone [closed] - iphone

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have drawn shapes, such as circles, rectangles, and triangle in context..
Now i want to move, rotate and scale that drawn shape.

I'm not sure how you're doing your drawing, but it looks like you need to start from the beginning. If you've drawn something in a UIView using 'drawPath', you can animate the view with methods like animateWithDuration: animations: completion:. Here's an example that will move a view up the screen and then remove it from the view.
CGRect endFrame = myView.frame; // get the original frame
endFrame.origin.y += 200; // move y-origin of the frame by 200.
// In this case, the animation consists of changing myView's current frame to
//endFrame over the course of 0.3 seconds. When the animation is complete,
//myView is removed from the screen.
[UIView animateWithDuration:0.3
animations:^{
myView.frame = endFrame ;
}
completion:^ (BOOL finished) {
if (finished) {
[myView removeFromSuperview];
}
}];
To get an idea of what you're doing, the view programming guide in the apple documentation is very useful, particularly the section on animations, UIView animations.

Related

Need to apply gesture in label view at fix corner point like ZDStckerView in objective c in iphone [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i want to implement text on image with resizing feature like i can zoom text field or label in or out by clicking a corner point of label...and i want to save that text on image view...
i refer sticker view ...but the label inside image does not zoom in or out...
code :
//add a label inside imageview
UILabel *lb1 = [[UILabel alloc ] initWithFrame:CGRectMake(0,0,320,40)];
UIimageview *imgview_sign = [[UIImageview alloc ] initWithFrame:CGRectMake(0,0,320,140)];
[imgview_sign addsubview:lbl1];
//add aZDSticker view
ZDStickerView *userResizableView = [[ZDStickerView alloc] initWithFrame:imgview_sign.frame];
userResizableView.tag = 0;
userResizableView.delegate = self;
userResizableView.contentView = imgview_sign;
userResizableView.preventsPositionOutsideSuperview = NO;
[userResizableView showEditingHandles];
[self.view addSubview:userResizableView];
//Imageview is zoomed properly in or out but my label is not zomming....i want to apply gesture on label also ...
You can try to draw text on uiimage, this should work.
Check this answer: https://stackoverflow.com/a/12578118/2298998

how to do expand and collapse uiview on IOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am very new to iPhone/iPad development. can you please help me create this programmatically. I want to expand/collapse a UIView programmatically.
Anyone know how to do it or any tutorial that i can follow? I have tried to find the tutorial but couldn't find what i want.
Below is the screenshot how i want to do
Its easily done with modify the height of that View as bneely suggested..
Follow the below steps:
1.First create the second View what you posted in your question and name it "detailedView"
2.if you have the "detailedView" height = 200(for example), write the following code in viewDidLoad method,
CGRect newFrame = detailedView.frame;
newFrame.size.height = 100;
detailedView.frame = newFrame;
so when the "detailedView" load, it will be looked like the first View what you showed in your question.
3.When you click the button to expand "detailedView", within that button action just write the following code
CGRect newFrame = detailedView.frame;
if(newFrame.size.height == 100)
{
newFrame.size.height = 200;
[UIView animateWithDuration:0.25 animations:^(void){
detailedView.frame = newFrame;
}];
}
else
{
newFrame.size.height = 100;
[UIView animateWithDuration:0.25 animations:^(void){
detailedView.frame = newFrame;
}];
}
That's all.
CGRect newFrame = view.frame;
newFrame.size.height += 100;
[UIView animateWithDuration:0.25 animations:^(void){
view.frame = newFrame;
}];

CGAffineTransform and scaling to center of the image

I started studying objective-c using the iPhone and iPad apps for Absolute Beginners by Rory Lewis book but i got stuck on the 5th chapter.
I want to make a button that shrinks an image.
My problem is, that after I wrote all the code, the image shrinks to the point (0, 0) of the UIImageView (the top left), while in the video the image shrinks to its center. I've done some research and found out that CGAffineTransform uses the center of the object to make translations, rotations etc.
So why does it not work in my case?
I have the latest Xcode version and haven't done anything strange.
I hope I've been clear. Sorry for my English.
EDIT
Sorry for the code, but i wrote the question from my phone.
Anyway the incriminated part goes something like this
- (IBAction)shrink:(id)sender {
if(hasShrink == NO){
[shrinkButton setTitle:#"Grow" forState:UIControlStateNormal];
}
else if(hasShrink == YES){
[shrinkButton setTitle:#"Shrink" forState:UIControlStateNormal];
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
myIcon.transform = CGAffineTransformMakeScale(.25, .25);
hasShrink = YES;
[UIView commitAnimations];
}
All the animations are correctly written and the app does work, it just shrinks to the top left. Why is the point not set to the center of the UIImageView by default like it should be?
EDIT:
I figured out it was a problem caused by AutoLayout.
Once disabled everything went smooth ;)
If you are transforming a view mangled managed by auto-layout, you may experience some strange side-effects. See this answer for more details.
The solution I ended up employing was to encapsulate the view I wanted to transform inside another view of exactly the same size. The outer view had the appropriate layout constraints applied to it while the inner view was simply centered in its container. Applying a CGAffineTransform scale transform to the inner view now centers properly.
Old question... but just in case others come looking:
The CGAffineTransform acts (rotates, scales) around an anchorPoint.
If you are sizing to 0, 0 then your anchor point is set to 0, 0. If you want it to size to a different point, such as the center of the image, you need to change the anchor point.
The anchor is part of a layer
So if you have a UIImageView called imageview, you would make a call like this to set the anchor to the center of imageview:
[imageview.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
Try something like this:
CGAffineTransform t = CGAffineTransformMakeScale(0.5, 0.5);
CGPoint center = imageView.center; // or any point you want
[UIView animateWithDuration:0.5
animations:^{
imageView.transform = t;
imageView.center = center;
}
completion:^(BOOL finished) {
/* do something next */
}];
Next time show your code. It will be easier to help you.
Check this project: https://github.com/djromero/StackOverflow/archive/Q-13706255.zip
You must study how autolayout and autoresize affect your views. In the project above both are disabled to let you see how it works.

Animate size of a UIView around center point

I have a UIView which I want to grow from it's center when a user touches it. The problem is that when animating it the view expands left and then moves to the right, whereas I want it to expand to the left and right, while keeping the center point the same.
This is the code I have at the moment:
[UIView animateWithDuration:1 animations:^(void) {
[view setFrame:CGRectMake(-10, 0, 320, view.frame.size.height)];
}];
I didn't think it was going to be difficult to do this, but it seems it is. Short of animating it manually with a timer I have no idea how to get it to expand from it's center.
I am not quite sure why it's working for you in a weird manner. Did you alter the anchorPoint property in any way? Otherwise it should grow from center.
Does doing
CGRect newFrame;
newFrame = CGRectInset(view.frame, -10, -30);
[UIView animateWithDuration:1 animations:^(void) {
view.frame = newFrame;
}];
also give you the same result? What about this?
[UIView animateWithDuration:1 animations:^(void) {
view.transform = CGAffineTransformScale(view.transform, 1.1, 1.1);
}];
Try the code given by #Deepak Danduprolu and also don't forgot to UnCheck the "Use AutoLayout" checkbox in the show file inspector window of the storyboard.
It works for me.
Just offset the X,Y position of the view. Lets say you're DECREASING both the width and height of the frame by 20 points: you should then ADD 10 points to both the X and Y position of the frame.

Alternative to CGAffineTransformConcat

In the app I'm working on the user taps on a tableview to zoom it up to full view from a "thumbnail" or a miniature view. Everything is working great except for a somewhat annoying animation glitch or whatever. The thing is I'm using the code below:
if ([subview respondsToSelector:#selector (name)] && [subview.name isEqualToString:self.labelListName.text])
{
[self.tabBarController.view addSubview:subview];
CGRect frame = CGRectMake(35, 78, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
subview.frame = frame;
CGAffineTransform scale = CGAffineTransformMakeScale(1.39, 1.39);
CGAffineTransform move = CGAffineTransformMakeTranslation(0,44);
CGAffineTransform transform = CGAffineTransformConcat(scale, move);
[UIView animateWithDuration:0.15
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
subview.transform = transform;
}
completion:^(BOOL finished){ [self goToList],subview.hidden = YES; }];
}
- (void)goToList
{
self.gotoWishList = [[WishList alloc] initWithNibName:#"WishList" bundle:nil];
self.gotoWishList.hidesBottomBarWhenPushed=YES;
self.gotoWishList.name = self.labelListName.text;
[self.navigationController pushViewController:self.gotoWishList animated:NO];
self.gotoWishList.scrollLists = self;
[WishList release];
}
And when doing the animation the transfer between the zoom view and the actual view the user is going to interact with is not completely perfect. The text inside the cell jumps a little when switching between the views. The problem lies in the translation matrix. If I skip that I can get the animation to work perfectly but then of course I need to move the miniature view down in the GUI which is not an option. If I instead do the animations in another order (move, scale) then it works better. I still get a jump at the end but it looks better, as everything jumps...and not just the text.
So...basically my question is how can I make this animation fluent. I read that the CGAffineTransformConcat still does each animation separately, and I really need both animations (scaling and moving the list) to be ONE fluent animation.
Thanks for any tips!
I think you will have to nest views/graphic-context to get what you want. The animation system doesn't support simultaneous animations because the mathematics of doing so requires an exponential amount of computational power. You might be able to trick it by sliding one view while enlarging the other.
I'm not sure about that as I have never had need to try it.
You might also be getting a jerk or skip from the tableview itself. The bounce at the top and end of scrolls can produce effects if you radically resize the table on the fly. I would turn all that off and see if you still have the problem. You might also want to test on the view independent of the tableview to make sure the problem is with the animations and not the tableview moving itself.