1

このを使用して、利用規約ボタンのポップアップを開きます。

開くときは機能しますが、閉じるとが得られexc bad access errorます。

私のアプリでstoryboardsは、これが閉じない問題である可能性があります

これは、ポップアップウィンドウクラスで使用するコードです。

  #import "MTPopupWindow.h"

 #define kShadeViewTag 1000

 @interface MTPopupWindow(Private)
 - (id)initWithSuperview:(UIView*)sview andFile:(NSString*)fName;
 @end

 @implementation MTPopupWindow


- (id)initWithSuperview:(UIView*)sview andFile:(NSString*)fName
{

self = [super init];
if (self) {
    // Initialization code here.
    bgView = [[UIView alloc] initWithFrame: sview.bounds];
    NSLog(@"%f",sview.bounds.size.width);
    NSLog(@"%f",sview.bounds.size.height);

    NSLog(@"%f",sview.bounds.origin.x);
    NSLog(@"%f",sview.bounds.origin.y);


    [sview addSubview: bgView];

    // proceed with animation after the bgView was added
    [self performSelector:@selector(doTransitionWithContentFile:) withObject:fName afterDelay:0.1];
}

return self;
}


 -(void)doTransitionWithContentFile:(NSString*)fName
{
//faux view
UIView* fauxView = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)];
[bgView addSubview: fauxView];

//the new panel
bigPanelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bgView.frame.size.width, bgView.frame.size.height)];
bigPanelView.center = CGPointMake( bgView.frame.size.width/2, bgView.frame.size.height/2);

//add the window background
UIImageView* background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"popupWindowBack1.png"]];
background.center = CGPointMake(bigPanelView.frame.size.width/2, bigPanelView.frame.size.height/2);
[bigPanelView addSubview: background];

//add the web view
int webOffset = 10;
UIWebView* web = [[UIWebView alloc] initWithFrame:CGRectInset(background.frame, webOffset, webOffset)];
web.backgroundColor = [UIColor clearColor];

if ([fName hasPrefix:@"http"]) {
    //load a web page
    web.scalesPageToFit = YES;
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: fName]]];
} else {
    //load a local file
    NSError* error = nil;
    NSString* fileContents = [NSString stringWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fName] encoding:NSUTF8StringEncoding error: &error];
    if (error!=NULL) {
        NSLog(@"error loading %@: %@", fName, [error localizedDescription]);
    } else {
        [web loadHTMLString: fileContents baseURL:[NSURL URLWithString:@"file://"]];
    }
}

[bigPanelView addSubview: web];

//add the close button
int closeBtnOffset = 10;
UIImage* closeBtnImg = [UIImage imageNamed:@"popupCloseBtn.png"];
UIButton* closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[closeBtn setImage:closeBtnImg forState:UIControlStateNormal];
[closeBtn setFrame:CGRectMake( background.frame.origin.x + background.frame.size.width - closeBtnImg.size.width - closeBtnOffset, 
                              background.frame.origin.y ,
                              closeBtnImg.size.width + closeBtnOffset, 
                              closeBtnImg.size.height + closeBtnOffset)];
[closeBtn addTarget:self action:@selector(closePopupWindow) forControlEvents:UIControlEventTouchUpInside];
[bigPanelView addSubview: closeBtn];

//animation options
UIViewAnimationOptions options = UIViewAnimationOptionTransitionFlipFromRight |
UIViewAnimationOptionAllowUserInteraction    |
UIViewAnimationOptionBeginFromCurrentState;

//run the animation
[UIView transitionFromView:fauxView toView:bigPanelView duration:0.5 options:options completion: ^(BOOL finished) {

    //dim the contents behind the popup window
    UIView* shadeView = [[UIView alloc] initWithFrame:bigPanelView.frame];
    shadeView.backgroundColor = [UIColor blackColor];
    shadeView.alpha = 0.3;
    shadeView.tag = kShadeViewTag;
    [bigPanelView addSubview: shadeView];
    [bigPanelView sendSubviewToBack: shadeView];
}];
}


-(void)closePopupWindow
{
//remove the shade
[[bigPanelView viewWithTag: kShadeViewTag] removeFromSuperview];   

//[self performSelector:@selector(closePopupWindowAnimate) withObject:nil afterDelay:0.1];

}


-(void)closePopupWindowAnimate
{

//faux view
__block UIView* fauxView = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)];
[bgView addSubview: fauxView];

//run the animation
UIViewAnimationOptions options = UIViewAnimationOptionTransitionFlipFromLeft |
UIViewAnimationOptionAllowUserInteraction    |
UIViewAnimationOptionBeginFromCurrentState;

//hold to the bigPanelView, because it'll be removed during the animation
    [UIView transitionFromView:bigPanelView toView:fauxView duration:0.5 options:options completion:^(BOOL finished) {

    //when popup is closed, remove all the views
    for (UIView* child in bigPanelView.subviews) {
        [child removeFromSuperview];
    }
    for (UIView* child in bgView.subviews) {
        [child removeFromSuperview];
    }

    [bgView removeFromSuperview];


}];
 }

 @end
4

0 に答える 0