【发布时间】:2011-11-18 10:20:32
【问题描述】:
我有一个应用程序,它以横向模式运行,我在手机上调试时将其保持在横向模式。我从主视图控制器上的 UIView 中获取中心值,我需要它来将项目放在屏幕的中心,因为它是通用的,所以我需要它是可变的,而不是设置为 iPhone 屏幕尺寸。
当我这样做并从 view.center 返回的 CGPoint 中读取 x 和 y 时,我得到 x = 170 y = 240
委托是我的应用程序中的一个视图控制器,中心功能是我想要移动到中心的对象之一。
- (void) center
{
CGPoint center = ((UIViewController*)delegate).view.center;
CGSize size = self.frame.size;
double x = center.x - size.width/2 - location.x;
double y = center.y - size.height/2 - location.y;
[self _move:1.0 curve:UIViewAnimationCurveEaseInOut x:x y:y];
}
- (void)_move: (NSTimeInterval)duration
curve:(int)curve x:(CGFloat)x y:(CGFloat)y
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
self.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
现在对我来说这没有多大意义。
【问题讨论】: