這是我在我的iOS程序中繪製節拍器圖像的功能。 當我加載它時,節拍器圖像被加載,但從屏幕的左上角向下「飛」到所需的位置。這不是我想要的行爲 - 我只是希望圖像出現在所需的位置。有人能告訴我爲什麼會發生這種情況,以及如何解決它? 非常感謝提前。iOS - 爲什麼我的UIImageView在移動?
碼頭。
- (void) drawMetronomeForBeat: (int) beatNumber withNumberOfBeats:(int) noBeats
{
// remove any previous instances first
if (metronomeImageView)
{
[metronomeImageView removeFromSuperview];
}
NSString * imageName = @"metronome";
NSString * noBeatsStr = [NSString stringWithFormat:@"%d", noBeats];
NSString * beatNumberStr = [NSString stringWithFormat:@"%d", beatNumber];
imageName = [imageName stringByAppendingString:noBeatsStr];
imageName = [imageName stringByAppendingString:@"b"];
imageName = [imageName stringByAppendingString:beatNumberStr];
UIImage* image = [UIImage imageNamed: imageName];
UIImageView * symbolImageView = [[UIImageView alloc] initWithImage:image];
[symbolImageView setFrame:CGRectMake(410.0f, 215.0f, symbolImageView.frame.size.width, symbolImageView.frame.size.height)];
metronomeImageView = symbolImageView;
[self.view addSubview:symbolImageView];
}
任何截圖? – holex 2012-07-24 08:11:21
嘗試刪除if語句(用它的正文),並用'[self.view addSubview:metronomeImageView]替換最後一行;' – benjammin 2012-07-24 08:14:29
不起作用...我意識到如果我直接在視圖代碼中繪製圖像沒有發生這種情況。雖然... – lppier 2012-07-24 12:12:17