objective c - Image translation in ios -
i not programmer if stupid question forgive me ! learning image transformation in ios want translate image 1 position on button click event here code...
- (ibaction)showinfobybutton:(id)sender { cgfloat v1 = imageview.center.x; cgfloat v2 = imageview.center.y; cgaffinetransform trans = cgaffinetransformtranslate(imageview.transform, v1, v2); imageview.transform = trans; }
what's wrong code. translate in y direction not in x. no matter how much set value v1 function don't care. thought what's going on ..... totally stucked give thanks help
in terms of question cgaffinetransform
, couple of thoughts:
are doing in init
method or viewdidload
? if so, may in view creation process many of uiview
related properties of imageview
(such center
) not reliable @ point. take , create sure you're getting non-zero values v1
, v2
. if want @ frame coordinates or like, might want defer until viewdidappear
or later.
are using autolayout? open storyboard or nib , @ document properties (below). if you're moving things around on screen, might want turn off.
as aside, setting v1
, v2
based upon center
of imageview
curious. you're moving center
amount of center
. you'd see following:
cgfloat dx = 100.0; cgfloat dy = 200.0; [uiview animatewithduration:1.0 animations:^{ cgaffinetransform trans = cgaffinetransformtranslate(self.someview.transform, dx, dy); imageview.transform = trans; }];
by way, animate (a) because that's improve user experience; , (b) when doing diagnostics this, makes easier me see it's changing , it's changing to. if don't want animation, don't utilize animatewithduration
code.
by way, if want move uiview
control, if you're not using autolayout, mutual way utilize animationwithduration
alter either center
or frame
, e.g.:
[uiview animatewithduration:1.0 animations:^{ imageview.center = cgpointmake(newx, newy); // set newx , newy whatever want }];
if you're using autolayout, process little more complicated. 1 technique in autolayout programmatically alter constraints, that's beyond scope of question.
ios objective-c
No comments:
Post a Comment