Ios-oc album, can enlarge, can't cycle view

Source: Internet
Author: User


#import "ViewController.h"


#define Kuan [UIScreen mainscreen].bounds.size.width

#define GAO [UIScreen mainscreen].bounds.size.height

@interface viewcontroller () <uiscrollviewdelegate>

@property (weak, nonatomic) Iboutlet uiscrollview *huakuang;


@end


@implementation Viewcontroller


-(void) viewdidload {

[super viewdidload];

// set contentsize

_huakuang. contentsize = Cgsizemake ((Kuan), Gao);

_huakuang. BackgroundColor =[uicolor blackcolor];

// Set Paging

_huakuang. pagingenabled = YES ;

// hide scroll bar

// whether the horizontal scroll bar is displayed when scrolling

_huakuang. Showshorizontalscrollindicator = NO ;

// whether vertical scroll bar is displayed when scrolling

_huakuang. Showsverticalscrollindicator = NO ;

// set up Agent , need to follow Agent agreement <UIScrollViewDelegate>, Written at the back of the @interface Viewcontroller ()

_huakuang. Delegate = Self ;

// Add a sub-view because it is multiple so write a method to implement the Add

[ self tianjianzishitu];

}

-(void) Tianjianzishitu

{

// If there are six images, create six Uiscrollview and six Uiimageview, and found six photos

for(int i=0;i<3;i++)

{

// create uiscrollview

// in order to separate different photos and add a black Edge, you need to set the scrollviewscroll View in the Width in left and View

uiscrollview *uisv=[[ uiscrollview alloc] INITW Ithframe:cgrectmake((Kuan+20) *i, 0, Kuan , Gao)];

// Add the creation to the total uiscrollview

[_huakuang addsubview: UISV];

// create uiimageview

uiimageview *uiiv=[[ uiimageview alloc] Init Withframe:cgrectmake(0, 0, Kuan, Gao )];

// add the created uiimageview to the uiscrollview

[uisv addsubview: Uiiv];

// set picture of Uiimageview

nsstring *imagename = [nsstring stringwithformat @ "new_feature_%d" , i + 1];

Uiiv. Image =[UIImage imagenamed: imageName];

// set tag value

Uiiv. Tag =1000;

// set up agent for Uiscrollview

UISV. Delegate = Self ;

// set zoom range

UISV. Minimumzoomscale =0.5;

UISV. Maximumzoomscale =1.5;

// define click events

uitapgesturerecognizer *tap=[[ uitapgesturerecognizer Alloc] initwithtarget : self Action: @selector(Dianjishijian:)];

// Set the number of active clicks ( just double-click )

tap. numberoftapsrequired =2;

// Add to uiscrollview

[uisv addgesturerecognizer: tap];

}

}

-(void) Dianjishijian: ( UITapGestureRecognizer *) Tap

{

// get view of click events

uiscrollview *uisv1= (uiscrollview *) tap. View ;

if(uisv1. Zoomscale !=1.0)

{

[Uisv1 setzoomscale: 1.0 animated:YES];

return ;

}

cgpoint location=[tap locationinview: Tap. View ];

cgrect rect=cgrectmake(location. x -100, location. y -100, (a);

[Uisv1 zoomtorect: Rect animated:YES];

}

// Specify a zoomed view

-(UIView *) Viewforzoominginscrollview: ( Uiscrollview *) scrollview{

if (ScrollView = = _huakuang) {

return nil;

}

uiimageview *imageview = (uiimageview *) [ScrollView Viewwithtag: +];

return ImageView;

}


// Scroll to the end and set the zoom scale of all zoom views to 1.0

-(void) scrollviewdidenddecelerating: ( Uiscrollview *) scrollview{

if (ScrollView = = _huakuang) {

for (id obj in _huakuang . subviews ) {

if ([obj iskindofclass: [uiscrollview class< /c7>]]) {

uiscrollview *scalesc = (Uiscrollview *) obj;

Scalesc.zoomscale = 1.0;

}

}

}

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

}


@end


This article is from the "Red Corner Antelope" blog, please be sure to keep this source http://2254359459.blog.51cto.com/10776102/1734363

Ios-oc album, can enlarge, can't cycle view

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.