【问题标题】:Implement IOS 7 zoom-in, zoom-out transition实现IOS 7放大、缩小过渡
【发布时间】:2014-08-24 10:41:12
【问题描述】:

我想在我的 ios 应用主屏幕中实现放大缩小过渡,就像 ios7 应用启动器中的过渡一样。

我不确定我是否走在正确的道路上,但我在主屏幕中创建了UIScrollView,并在滚动视图中创建了按钮。我将其中一个按钮的矩形框传递给zoomToRect,但没有进行缩放。

我的计划是切换到我的应用程序的另一个视图,以及填充屏幕的按钮上的放大动画。

我在使用UIScrollViewzoomToRect 时遗漏了什么,或者我在主屏幕上使用滚动视图时完全错误。我可以通过使用UIView 作为我的应用程序的主屏幕,然后使用CGAffineTransformMakeScale 转换来实现放大效果。

【问题讨论】:

    标签: ios objective-c uiscrollview


    【解决方案1】:

    1.在您的故事板上,将 uiscrollView 放在视图控制器上。 2.将uiimageView放在uiscrollView上 3.确保您的故事板不在自动布局上。 4.在你的显示尺寸检查器上,确保你的滚动视图和图像视图的高度和高度是相同的。 5.确保Autosize引脚都被点击。

    转到分配给您正在处理的 ViewController 的 UIViewContoller 类。

    在头文件中添加以下属性:

             #import <UIKit/UIKit.h>
    
            @interface ViewController : UIViewController <UIScrollViewDelegate>
    
    
            @property (nonatomic, strong) UIImageView* imageViewPointer;
    //Make sure scrollView is linked to the ui element on your storyboard
            @property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
    //Make sure imageView is linked to the ui element on your storyboard
            @property (strong, nonatomic) IBOutlet UIImageView *imageView;
    
            // These properties are new
            @property (nonatomic, strong) NSMutableArray* imageViewConstraints;
            @property (nonatomic) BOOL imageViewConstraintsNeedUpdating;
            @property (nonatomic, strong) UIScrollView* scrollViewPointer;
    
        //Then in the implementation file this the following code to implement
    
        @interface ViewController ()
    
        @end
    
        @implementation ViewController
    
        @synthesize scrollView,imageView;
    
        - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
        {
            return self.imageViewPointer;
        }
    
    
    
        - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
        {
            if(_imageViewConstraintsNeedUpdating)
            {
                // Remove the previous image view constraints
                [self.view removeConstraints:_imageViewConstraints];
    
                // Replace them with new ones, this time constraining against the width & height of the scroll view's content, not the scroll view itself
                NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_scrollViewPointer, _imageViewPointer);
                [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_imageViewPointer(width)]|" options:0 metrics:@{@"width" : @(_scrollViewPointer.contentSize.width)} views:viewsDictionary]];
                [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_imageViewPointer(height)]|" options:0 metrics:@{@"height" : @(_scrollViewPointer.contentSize.height)} views:viewsDictionary]];
    
                self.imageViewConstraintsNeedUpdating = NO;
            }
        }
    
    
    
        - (void)viewDidLoad
        {
            [super viewDidLoad];
            // Do any additional setup after loading the view.
    
    
            [imageView setImage:[UIImage imageNamed:@"Your Image"]];
    
            imageView.contentMode = UIViewContentModeScaleAspectFit;
    
           scrollView.contentInset = UIEdgeInsetsZero;
    
            self.imageViewPointer = imageView;
    
            // New
            self.scrollViewPointer = scrollView;
            scrollView.maximumZoomScale = 5;
            scrollView.minimumZoomScale = 1.0;
            scrollView.delegate = self;
    
            NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(scrollView, imageView);
            NSLog(@"Current views dictionary: %@", viewsDictionary);
            [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
            [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: 0 views:viewsDictionary]];
    
            // Saving the image view width & height constraints
            self.imageViewConstraints = [[NSMutableArray alloc] init];
            // Constrain the image view to be the same width & height of the scroll view
            [_imageViewConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView(scrollView)]|" options:0 metrics: 0 views:viewsDictionary]];
            [_imageViewConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView(scrollView)]|" options:0 metrics: 0 views:viewsDictionary]];
    
            // Add the image view constraints to the VIEW, not the scroll view
            [self.view addConstraints:_imageViewConstraints];
    
            // Flag
            self.imageViewConstraintsNeedUpdating = YES;
    
    
        }
    
        @end
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多