2010-11-21 38 views
1

嘿,大家好...今天是我第一天在iPhone SDK上砍掉。有一个爆炸,但有一个快速的问题。移动一个UIView - 新手iphone sdk

我想通过从滑块发送信息动态地在屏幕上移动UIView。我的滑块工作正常,但我似乎无法弄清楚如何让UIView移动。

我.h文件中...


@interface Slider_BallViewController : UIViewController 
{ 
    IBOutlet UISlider *theslider; 
    IBOutlet UITextField *ytext; 
    IBOutlet UIView *theball; 
} 
- (IBAction)moveVert:(id)sender; 

我的.m文件...


- (IBAction)moveVert:(id)sender 
{ 
int progressAsInt = (int)(theslider.value); 
NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt]; 
ytext.text = newText; 

theball.frame.origin.y += progressAsInt; 
} 

我上frame.origin行的错误在我的.m文件,说。左值操作数赋值需要左值。不知道我做错了什么。

任何帮助是伟大的,谢谢。

alt text

回答

2

如果要修改一个UIView的框架财产,则应按照以下操作步骤:

CGRect curFrame = theball.frame; 
curFrame.origin.y += progressAsInt; 
theball.frame = curFrame; 
+0

惊人的,非常感谢红牛。 – barry 2010-11-21 03:44:17

+0

不客气。 – AechoLiu 2010-11-21 07:44:26