本文转自:www.cppblog.com/zhangyuntaoshe/articles/122787.html
UIImage
其实,UIImageVIew为UIImage的视图容器.
3.UIImage 与UIImageView的重要属性:
UIImage:
重要属性:
size
imageOrientation
重要方法:
+imageNamed:
+imageWithData:
drawAtPoint:
drawAtPoint:blendMode:alpha:
drawInRect:
drawInRect:blendMode:alpha:
UIImageView:
重要属性:
image
animationImages
重要方法:
initWithImage:
1.使用UIImageView来播放动画.
-(void)viewDidLoad
{
[superviewDidLoad];
self.title=NSLocalizedString(@"ImagesTitle",@"");
//setupourUIImagewithagrouporarrayofimagestoanimate(orinourcaseaslideshow)
self.imageView.animationImages=[NSArrayarrayWithObjects:[UIImageimageNamed:@"scene1.jpg"],[UIImageimageNamed:@"scene2.jpg"],[UIImageimageNamed:@"scene3.jpg"],[UIImageimageNamed:@"scene4.jpg"],[UIImageimageNamed:@"scene5.jpg"], nil ];
imageView.animationDuration=5.0;
[self.imageViewstopAnimating];
//Settheappropriateaccessibilitylabels.
[self.imageViewsetIsAccessibilityElement:YES];
[self.imageViewsetAccessibilityLabel:self.title];
[self.slidersetAccessibilityLabel:NSLocalizedString(@"DurationSlider",@"")];
}
2.使用UIScrollView来对子视图UIImageView进行操作,移动,放大及缩小.
通过viewForZoomingInScrollView返回需要放大缩小的view,由UIScrollView完成对View的放大缩小和移动功能。
//UIScrollViewDelegate ...
-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView
{
return[self.viewviewWithTag:201];
}
/**/
-(void)scrollViewDidEndZooming:(UIScrollView*)scrollViewwithView:(UIView*)viewatScale:(float)scale
{
NSLog(@"Thescrollview'ssizeis(%f,%f):",scrollView.frame.size.width,scrollView.frame.size.height);
NSLog(@"Thescrollview'scontentsizeis(%f,%f):",scrollView.contentSize.width,scrollView.contentSize.height);
UIImageView*temp=(UIImageView*)[self.viewviewWithTag:201];
NSLog(@"Thescrollview'ssubviewsizeis(%f,%f):",temp.frame.size.width,temp.frame.size.height);
}
-(void)viewDidLoad
{
self.navigationController.navigationBar.tintColor=COOKBOOK_PURPLE_COLOR;
self.weathermap=URLIMAGE(MAP_URL);
self.title=@"WeatherScroller";
//Createthescrollviewandsetitscontentsizeanddelegate
UIScrollView*sv=[[[UIScrollViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,320.0f,284.0f)]autorelease];
sv.contentSize=self.weathermap.size;
sv.delegate=self;
//Createanimageviewtoholdtheweathermapandaddittothescrollview
UIImageView*iv=[[[UIImageViewalloc]initWithImage:self.weathermap]autorelease];
iv.userInteractionEnabled=YES;
iv.tag=201;
//Calculateandsetthezoomscalevalues
floatminzoomx=sv.frame.size.width/self.weathermap.size.width;
floatminzoomy=sv.frame.size.height/self.weathermap.size.height;
sv.minimumZoomScale=MIN(minzoomx,minzoomy);
sv.maximumZoomScale=3.0f;
//Addinthesubviews
[svaddSubview:iv];
[self.viewaddSubview:sv];
}
3.UIScrollView 的 scrollRectToVisible: 方法的使用:(代码滑动scrollView)
-(void)viewDidLoad{
[superviewDidLoad];
scrollView1=[[UIScrollViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,320.0f,480)];
[scrollView1setContentSize:CGSizeMake(320*3,400)];
[scrollView1setPagingEnabled:YES];
scrollView1.showsHorizontalScrollIndicator=NO;
[scrollView1setClipsToBounds:YES];
UIView*view1=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,480)];
[view1setBackgroundColor:[UIColorredColor]];
UIView*view2=[[UIViewalloc]initWithFrame:CGRectMake(320,0,320,480)];
[view2setBackgroundColor:[UIColoryellowColor]];
UIView*view3=[[UIViewalloc]initWithFrame:CGRectMake(320*2,0,320,480)];
[view3setBackgroundColor:[UIColorblueColor]];
[scrollView1addSubview:view1];
[scrollView1addSubview:view2];
[scrollView1addSubview:view3];
//[self.viewaddSubview:scrollView1];
[self.view insertSubview:scrollView1atIndex:0];
[view1release];
[view2release];
[view3release];
[scrollView1release];
//启动时钟来动态更改视图.
[NSTimerscheduledTimerWithTimeInterval:3
target:self
selector:@selector(scrollToRight)
userInfo:nil
repeats:YES];
}
-(void)scrollToRight
{
staticintindex=0;
if(index<2)
{
index++;
CGRectframe=scrollView1.frame;
frame.origin.x=320*index;
frame.origin.y=0;
[scrollView1scrollRectToVisible:frameanimated:YES];
}
else
{
scrollView1.contentOffset=CGPointMake(0,0);
//[scrollView1scrollRectToVisible:CGRectMake(0,0,320,480)animated:YES];
index-=3;
}
}