开发者

How center a movie item on a view in SDK for iPad application

I need to center a movie on a view on my iPad.

Well I've used this command in xcode 4:

player =[[MPMoviePlayerController alloc]
                              initWithContentURL:[NSURL URLWithString:movieUrl]];

[[NSNotificationCenter defaultCenter]
       addObserver:self
          selector:@selector(movieFinishedCallback:)
              name:MPMoviePlayerPlaybackDidFinishNotification
            object:player];

[[player view] setFrame:CGRectMake(30.0, 250.0, 650.0,506.0)];

Now are there a way like this syntax setFrame:

CGRectMake(self.view.width /2, 250.0, 650.0,506.0)];

In other language like Actionscript 开发者_开发问答I can intercept the size of my view and divide it for 2 to center an Item.

someone can help me please?

thanks


Similar to what Joe said, but:

player.view.center = self.view.center;


Andre's answer is the easiest way to center a view both vertically and horizontally. But if you are trying to just center it in one direction access the size of your view through the values from the view's frame or bounds like so:

player.view.bounds.size.width
player.view.frame.size.width

Either will work for size. The difference is that the bounds rectangle is measured in the view's own coordinate system so its origin is typically 0,0. The frame is the view's rectangle in its parent view's coordinate system, so the origin is the upper left corner coordinate of your view. Both bounds and frame typically have the same size (though in some special cases that may not be true).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜