我的目標很簡單;我想創建一個顯示UIImage的程序,當從下到上滑動時,顯示另一個UIImage。這裏的圖像可能是一個快樂的臉/悲傷的臉。悲傷的面孔應該是出發點,幸福的臉孔應該是終點。當用手指滑動時,手指下面的部分應該顯示愉快的臉。界限和框架:如何顯示UIImage的一部分
到目前爲止,我嘗試用UIImageview的框架和邊界屬性來解決這個問題,我用它來表達歡樂的臉部圖像。
這段代碼做錯了什麼,因爲過渡開始於屏幕中心而不是底部。請注意,框架和界限的起源都是0,0 ...
我已經閱讀了許多關於框架和邊界的頁面,但我不明白。任何幫助表示讚賞!
loadimages只被調用一次。
- (void)loadImages {
sadface = [UIImage imageNamed:@"face-sad.jpg"];
happyface = [UIImage imageNamed:@"face-happy.jpg"];
UIImageView *face1view = [[UIImageView alloc]init];
face1view.image = sadface;
[self.view addSubview:face1view];
CGRect frame;
CGRect contentRect = self.view.frame;
frame = CGRectMake(0, 0, contentRect.size.width, contentRect.size.height);
face1view.frame = frame;
face2view = [[UIImageView alloc]init];
face2view.layer.masksToBounds = YES;
face2view.contentMode = UIViewContentModeScaleAspectFill;
face2view.image = happyface;
[self.view addSubview:face2view];
frame = CGRectMake(startpoint.x, 0, contentRect.size.width, contentRect.size.height);
face2view.frame = frame;
face2view.clipsToBounds = YES;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint movepoint = [[touches anyObject] locationInView: self.view];
NSLog(@"movepoint: %f %f", movepoint.x, movepoint.y);
face2view.bounds = CGRectMake(0, 0, 320, 480 - movepoint.y);
}
UIImages和UIImageView在dealloc函數中正確處理。
我想我需要把圖像幀放在左上角。這是因爲圖像必須重疊(它們是相同的圖像,所以如果我把它放在任何其他地方,幸福的臉相對於悲傷的臉就會移動)。有什麼方法可以從底部開始顯示快樂的臉? – 2010-12-10 16:30:45