uiscrollview-big Picture Show and picture Zoom Demo

Source: Internet
Author: User

A big Picture Show

#import "MJViewController.h"

@interface Mjviewcontroller ()

{

Uiscrollview *_scrollview;//side But global calls are defined as member variables

}

@end

@implementation Mjviewcontroller

-(void) viewdidload

{

[Super Viewdidload];

1. Create Uiscrollview

Uiscrollview *scrollview = [[Uiscrollview alloc] init];

Scrollview.frame = CGRectMake (0, 0, 250, 250); Size in frame refers to the visual range of the Uiscrollview

Scrollview.backgroundcolor = [Uicolor Graycolor];

[Self.view Addsubview:scrollview];

2. Create Uiimageview (image)

Uiimageview *imageview = [[Uiimageview alloc] init];

Imageview.image = [UIImage imagenamed:@ "big.jpg"];

CGFloat IMGW = imageView.image.size.width; The width of the picture

CGFloat imgh = imageView.image.size.height; The height of the picture

Imageview.frame = CGRectMake (0, 0, IMGW, IMGH);

[ScrollView Addsubview:imageview];

3. Setting the properties of the ScrollView

Sets the scrolling range (content size) of the Uiscrollview

Scrollview.contentsize = imageView.image.size;

Hide Horizontal scroll bar

Scrollview.showshorizontalscrollindicator = NO;

Scrollview.showsverticalscrollindicator = NO;

Used to record the location of ScrollView scrolling

Scrollview.contentoffset =;

Remove the Spring effect

Scrollview.bounces = NO;

Add extra scrolling Area

Top left bottom Right

Scrollview.contentinset = Uiedgeinsetsmake (20, 20, 20, 20);

_scrollview = ScrollView;

}

-(Ibaction) Down: (UIButton *) Sender {

[UIView animatewithduration:1.0 animations:^{

This method controls the scrolling effect of the button under the body, here is the Y value of changing the _scrollview.contentoffset

Cgpoint offset = _scrollview.contentoffset;

Offset.y + = 150;

_scrollview.contentoffset = offset;

_scrollview.contentoffset = cgpointmake (0, 0);

}];

}

@end

Two picture zoom

//

Mjviewcontroller.m

02-uiscrollview02-Picture Zoom

//

Created by Apple on 13-11-27.

Copyright (c) 2013 itcast. All rights reserved.

//

#import "MJViewController.h"

@interface Mjviewcontroller () <UIScrollViewDelegate>

{

Uiimageview *_imageview;

}

@end

@implementation Mjviewcontroller

-(void) viewdidload

{

[Super Viewdidload];

1. Add Uiscrollview

Uiscrollview *scrollview = [[Uiscrollview alloc] init];

Scrollview.frame = CGRectMake (0, 0, 320, 460);

Scrollview.frame = Self.view.bounds;

[Self.view Addsubview:scrollview];

2. Add a picture

UIImage *image = [UIImage imagenamed:@ "big.jpg"];

Call Initwithimage: Method created by the Uiimageview, its width is the same as the width of the picture is the same as the height

_imageview = [[Uiimageview alloc] initwithimage:image];

Set up a picture

Imageview.image = [UIImage imagenamed:@ "big.jpg"];

//

Set frame

Imageview.frame = CGRectMake (0, 0, imageView.image.size.width, imageView.image.size.height);

[ScrollView Addsubview:_imageview];

Set Content Scope

Scrollview.contentsize = image.size;

Set proxy objects for ScrollView

Scrollview.delegate = self;

Set Maximum scaling ratio

Scrollview.maximumzoomscale = 2.0;

Set the minimum scaling scale

Scrollview.minimumzoomscale = 0.2;

}

Proxy methods for #pragma mark-uiscrollview

#pragma mark this method returns a control that can be used for pinch gesture scaling operations

#pragma mark will call when Uiscrollview attempts to scale.

-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView

{

return _imageview;

}

#pragma mark calls when zoom is complete

-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (float) scale

{

NSLog (@ "End Zoom-%f", scale);

}

#pragma mark is calling when zooming.

-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView

{

NSLog (@ "-----");

}

@end

uiscrollview-big Picture Show and picture Zoom Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.