Que*_*low 2 iphone objective-c scrollview ios
我必须缩放图像UIScrollView和缩放后我想裁剪可见的图像UIImageView.我有以下问题:
1)图像不缩放,viewForZoomingInScrollView方法未调用.
2)这是关于裁剪的第二个问题,第一个问题就在这里.如何在缩放后裁剪缩放图像?
我的代码是:
@interface ViewController : UIViewController<UIScrollViewDelegate>
{
UIImageView *imageView1;
UIScrollView *scroll;
}
@property(nonatomic,retain) UIImageView *imageView1;
@end
Run Code Online (Sandbox Code Playgroud)
并在.m文件中
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect frame1 = CGRectMake(10,10,190,200);
self.imageView1.userInteractionEnabled = YES;
imageView1=[[UIImageView alloc]initWithFrame:frame1];
imageView1.contentMode = UIViewContentModeScaleToFill;
imageView1.image= [UIImage imageNamed:@"back.jpeg"];
CGRect frame = CGRectMake(10,10,190,200);
scroll = [[UIScrollView alloc] initWithFrame:frame];
scroll.contentSize = CGSizeMake(240, 260);
scroll.showsHorizontalScrollIndicator = YES;
scroll.showsVerticalScrollIndicator = YES;
scroll.clipsToBounds = YES;
scroll.backgroundColor=[UIColor blackColor];
[scroll addSubview:imageView1];
[imageView1 release];
scroll.minimumZoomScale = 0.55;
scroll.maximumZoomScale = 2.0;
scroll.delegate=self;
[self.view addSubview:scroll];
self.imageView1.userInteractionEnabled = YES;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
NSLog(@"delegate method called");
return self.imageView1;
}
Run Code Online (Sandbox Code Playgroud)
实现UIScrollViewDelegate并在控制器的ViewDidLoad中调用此函数.
-(void)setContentSizeForScrollView
{
scrollView.contentSize = CGSizeMake(YOURIMAGEVIEW.frame.size.width, YOURIMAGEVIEW.frame.size.height);
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 5.0;
}
Run Code Online (Sandbox Code Playgroud)
并编写此功能
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return YOURIMAGEVIEW;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4929 次 |
| 最近记录: |