0

2番目のビューがポップアップのように表示されるよりもbarButtonをクリックすると、ViewControllerに1つのViewControllerと1つのUIViewがあります。2番目のビューにPageControllerとScrollViewを追加したいのですが、2番目のビューはUIViewControllerではなく、UIView.soです。どうやってやるの...

私の最初のビューは「ImageViewController」で、2番目のビューは「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;
}
4

1 に答える 1

0

ページ コントロールを使用したスクロール ビューの 2 番目のビューで、次のように実装します (この例は、2 つのビューのシナリオを示しています)。

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];

view1/2 は任意のビジュアル要素に置き換えることができます。ページコントロールでスクロールするには、スクロールビューに追加するすべてのビューが同じ幅/高さであることを確認してください。そうすれば、すぐに使用でき、何もする必要はありません。また、ユーザーになんらかのフィードバックを提供するために、UIPageControl をビューに追加することを常にお勧めします。ただし、オプションです。

もう1つ、ページコントロールで水平スクロールが必要な場合は、上記のように幅を増やしてください。垂直スクロールが必要な場合は、高さを増やして幅を同じに保ちます。

于 2012-12-04T13:49:36.460 に答える