アプリ内で UILabel を移動していますが、場所をジャンプするのではなく、数フレームにわたって場所とサイズを変更したいと考えています。Iphone 用の Objective-c とココア開発を使用しています。誰でも私を助けることができますか?
3558 次
2 に答える
9
最も簡単な方法は次のとおりです。
CGRect endFrame = /*The frame of your label in end position*/
[UIView animateWithDuration:0.5 animations:^{
myLabel.frame = endFrame;
}];
于 2012-07-27T02:34:02.580 に答える
3
このコードはあなたの問題に役立ちます
#define FONT_SIZE 14
#define DURATION 10
#define DELAY 10
-(void)viewWillAppear:(BOOL)animated {
NSString* string = @"My Label";
CGSize framesize = [string sizeWithFont:[UIFont fontWithName:@"Copperplate" size:FONT_SIZE]];
// Origin
float x0 = 0;
float y0 = 0;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat appFrameWidth = appFrame.size.width;
CGFloat appFrameHeight = appFrame.size.height;
// Destination
float x1 = appFrameWidth - framesize.width;
float y1 = appFrameHeight - framesize.height;
UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(x0, y0, framesize.width, framesize.height)];
label.backgroundColor = [UIColor clearColor];
label.text = string;
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(1,2);
label.font = [UIFont fontWithName:@"Copperplate" size:FONT_SIZE];
[self.view addSubview:label];
[UIView animateWithDuration:DURATION
delay:DELAY
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
label.frame = CGRectMake(x1, y1, framesize.width, framesize.height);
}
completion:^(BOOL finished){
[label removeFromSuperview];
}];
}
于 2012-07-27T04:57:50.290 に答える