1

I am trying to slide an image from off the screen onto the screen from the left and stopping at the center point in the view. I would like to keep it contrained at the y position if possible (IE image is set in story board).

I am reading this tutorial, but it is in swift and I cannot make the same assignments in objective-c.

http://www.raywenderlich.com/95910/uiview-animation-swift-tutorial

It says to set the view off the screen (in swift):

heading.center.x  -= view.bounds.width

Then animate (in swift):

UIView.animateWithDuration(0.5, animations: {
    self.heading.center.x += self.view.bounds.width
})

However I cannot manipulate center.x in objective c like they are doing in swift.

I have tried adjusting the initial position of the image in viewWillAppear by changing the bounds with no luck.

EDIT:

Here is what I am trying to get it positioned off the screen:

self.heading.center = CGPointMake(-200, self.heading.center.y);

No matter how negative I set the x position the view will still appears on the screen. Actually no matter what I set x position to the view does not move in the x direction at all. I have also tried to set the frame

4

2 に答える 2

1

ビューの中心のx座標は、Objective-C で直接割り当てることはできません。代わりに、全体として中心点を設定してみてください。あなたの例では、これは次のようになります。

[UIView animateWithDuration:0.5 animations:^{
    CGFloat newCenterX = self.heading.center.x + self.view.bounds.size.width;
    self.heading.center = CGPointMake(newCenterX, self.heading.center.y);
}];
于 2015-06-07T22:32:09.657 に答える