【发布时间】:2014-07-20 01:35:28
【问题描述】:
我有一个与iPhone: Expand UITextView when scrolling 非常相似的问题
我的应用程序还应该在详细视图顶部有一个图片,在它下面有一个文本视图。滚动图片时应该缩小,以便为文本提供更多空间。可以在 Shazam 或 Rdio 等音乐应用中找到微笑效果,专辑封面位于顶部,专辑信息位于下方。
到目前为止,我设法通过使用- (void)scrollViewDidScroll:(UIScrollView *)scrollView 来调整图片大小,但它只有在 UIImageView 设置为 Aspect Fit 时才有效,但我需要它是 Aspect Fill,因为我不希望在调整框架大小时图片被挤压。
谁能帮我实现这个效果?
这是我目前使用的。我对编程很陌生,所以如果您对我编写的代码有任何其他的 cmet,我也非常感谢!
Viewcontroller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController < UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
Viewcontroller.m
@interface ViewController ()
{
CGFloat draggedOffsetY;
CGFloat newHeight;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.scrollView setContentSize:CGSizeMake(320, 800)];
CGPoint offset = CGPointMake(0, 0);
[self.scrollView setContentOffset:offset];
self.scrollView.delegate = self;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
draggedOffsetY = self.scrollView.contentOffset.y;
NSLog(@"View was dragged to: %f", draggedOffsetY);
newHeight = self.imageView.frame.size.height-draggedOffsetY;
if (newHeight > 75 && newHeight < 150 ){
[self.imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width, newHeight)];
CGFloat topCoordiate = self.imageView.frame.size.height;
self.textView.frame = CGRectMake(0, topCoordinate, self.textView.frame.size.width, self.textView.frame.size.height);
}
}
【问题讨论】:
标签: ios cocoa-touch uiimageview resize scroll