1
好吧,這是我的困境,我發現這很奇怪,而且我很無知。我有一個應用程序,它運行在橫向模式下,當我在手機上進行調試時,我將其保持橫向模式。我從我的主視圖控制器上的UIView獲取中心值,我需要這個將項目放在屏幕中心,因爲它是通用的,所以我需要這個值是可變的,而不是設置爲iPhone屏幕大小。風景模式UIView.center給出了Potrait模式座標
當我做到這一點,並宣讀了由CGPoint返回view.center 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];
}
現在對我來說這沒有多大意義。有任何想法的人如何解決這個問題?
[UIView width and height reversed]的可能重複項(http://stackoverflow.com/questions/8141278/uiview-width-and-height-reversed) – jrturton