0

我对编程和目标 C 非常陌生,所以你必须对我放轻松。我确信应用程序中的某些代码可能是不必要的。我在谷歌和 StackOverflow 上搜索了答案,但没有一个解决方案对我有用,要么是因为它们不是正确的解决方案,要么我只是误解了答案。

问题是,当我添加一个很长的图像并且我只想垂直滚动时,它最初拒绝滚动,直到我更改一个名为“垂直空间(-1678)-滚动视图-图像视图-标尺图片的“约束” .png" 为 0,原因我不知道。我什至不明白为什么它默认为-1678。

无论如何,它可以完美地工作,直到我UIButton在情节提要中添加一个(我稍后想添加一个模态“动作转场”,以便它转到另一个视图)。当我添加UIButton它时,它根本不会在模拟器中滚动。

我想我一定是做错了什么,因为我只输入了关于按钮的一行代码(声明它),或者我可能必须输入更多代码才能滚动。我不知道!如果您需要更多信息以提供帮助,我将很乐意提供。我厌倦了试图让它发挥作用。提前致谢。

视图控制器.h

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate, UIScrollViewDelegate> {

ADBannerView *adView;
BOOL bannerIsVisible;
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *imageView;
IBOutlet UIButton *proVersion;

}

@property (nonatomic, assign) BOOL bannerIsVisible;
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;

@end

视图控制器.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize bannerIsVisible;
@synthesize scrollView;
@synthesize imageView;

- (void)viewDidLoad
{
[super viewDidLoad];

// Hide status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES];

// iAd:
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50.0f);
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;

}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {

    [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0, 50.0f);
    [UIView commitAnimations];
    self.bannerIsVisible = YES;

    }
}

 -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {

    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    banner.frame = CGRectOffset(banner.frame, 0, -50.0f);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;

}
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
4

2 回答 2

0

我玩了一下并摆弄了答案中的示例,然后得到了以下代码:

scrollView.contentSize = CGSizeMake(320,2246);

哪个有效!我花了几天的时间来解决这个问题,这只是一小行代码。我把它放到 viewDidLoad 中,突然它开始滚动了。我还不得不打开“AutoLayout”。

于 2013-04-29T06:40:01.557 回答
0

您将需要设置 的ContentSizeScrollView如下所示:

[scrollView setContentSize:CGSizeMake(320, 500)];
于 2013-04-28T18:04:42.070 回答