Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 要在ios中以编程方式在UIView中实现UIPageController和UIScrollView吗_Iphone_Objective C_Ios_Cocoa Touch - Fatal编程技术网

Iphone 要在ios中以编程方式在UIView中实现UIPageController和UIScrollView吗

Iphone 要在ios中以编程方式在UIView中实现UIPageController和UIScrollView吗,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,我现在有一个视图控制器和一个UIView在我的ViewController中,当我单击barButton时,第二个视图将弹出一个类似的弹出窗口,现在我想在第二个视图中添加页面控制器和滚动视图,我的第二个视图不是UIViewController,而是UIView。那么我该怎么做呢 我的第一个视图是“ImageViewController”,第二个视图是“PopupView” 在ImageViewController.m中 #import "PopupView.h" @implementation

我现在有一个视图控制器和一个UIView在我的ViewController中,当我单击barButton时,第二个视图将弹出一个类似的弹出窗口,现在我想在第二个视图中添加页面控制器和滚动视图,我的第二个视图不是UIViewController,而是UIView。那么我该怎么做呢

我的第一个视图是“ImageViewController”,第二个视图是“PopupView”

在ImageViewController.m中

#import "PopupView.h"

@implementation ImageViewController

- (void)viewDidLoad
{
UIBarButtonItem *clipArt = [[UIBarButtonItem alloc] initWithTitle:@"Clip Art"
                                                                style:UIBarButtonItemStyleBordered  
                                                               target:self
                                                               action:@selector(popUpView:)];
}

- (void)popUpView:(id)sender {
    CGRect * imageFrame = CGRectMake(10, 90, 300, 300);
    PopupView *popUpView = [[PopupView alloc] initWithFrame:imageFrame];
    [self.view addSubview:popUpView];

}
在PopupView.m中

- (id)initWithFrame:(CGRect)frame
{


    if (self) {
        CGRect * imageFrame = CGRectMake(0, 0, 300, 300);
        self = [super initWithFrame:frame];
        UIImageView *starImgView = [[UIImageView alloc] initWithFrame:imageFrame]; //create ImageView 

        starImgView.alpha =0.8;
        starImgView.layer.cornerRadius = 15;
        starImgView.layer.masksToBounds = YES;
        starImgView.image = [UIImage imageNamed:@"black"];

        [self addSubview:starImgView];
        self.backgroundColor = [UIColor clearColor];
}
    return self;
}

在第二个视图中,对于带有页面控制的滚动视图,实现如下操作(此示例演示了两个视图的场景):

可以用任何视觉元素替换view1/2。要使用页面控件进行滚动,请确保要添加到scrollview的所有视图的宽度/高度都相同。这样,它就可以开箱即用,你不必做任何事情。此外,将UIPageControl添加到视图中,以向用户提供某种反馈,这始终是一个好主意。但这是可选的


还有一件事,如果你想水平滚动页面控制,增加宽度如上所述。如果您想要垂直滚动,请增加高度并保持宽度不变。

请不要滥用Xcode标记。什么标记,我没有做任何…您在这个问题中使用了“Xcode”标记,而它与Xcode无关。以后请不要这样做。。我很抱歉,在一段时间内,我正在考虑它,所以,做了那个错误,对不起。。。
CGRect scrollViewFrame = CGRectMake(ur dimensions for scroll view);
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
myScrollView.pagingEnabled = YES;
myScrollView.contentSize = CGSizeMake(scrollViewFrame.size.width * 2, scrollViewFrame.size.height);
//content size is the actual size of the content to be displayed in the scroll view. 
//Since, here we want to add two views so multiplied the width by two.

CGRect viewFrame = [myScrollView bounds];

UIView *view1 = [[UIView alloc] initWithFrame:viewFrame];

viewFrame.origin.x = viewFrame.size.width; //setting the offset so that view2 is next to view 1
UIView *view2 = [[UIView alloc] initWithFrame:viewFrame];

//add both the view to scroll view
[myScrollView addSubview:view1];
[myScrollView addSubview:view2];

//add scroll view to parent view
[self addSubview:myScrollView];