2013-04-28 37 views
0

我很新的編程和客觀的C,所以你必須對我容易。我相信應用中的一些代碼可能是不必要的。我搜索谷歌和StackOverflow的答案,但沒有解決方案爲我工作,要麼是因爲他們不是正確的解決方案,或者我只是誤解了答案。添加一個UIButton到一個UIScrollView停止滾動

問題是,當我添加一個很長的圖像並且我想垂直滾動時,它最初拒絕滾動,直到我更改名爲「Vertical Space(-1678)」的「約束」 - 滾動視圖 - 圖像查看 - Ruler pic.png「爲0,原因不明。我甚至不明白爲什麼它默認爲-1678。

無論如何,它直到我在故事板中添加一個UIButton(我後來希望添加一個模式「動作segue」,以便它會轉到另一個視圖),它完美地工作。當我添加UIButton時,它將不會在模擬器中滾動。

我想我必須做錯了什麼,因爲我只輸入了一行代碼(聲明它)關於按鈕,或者我可能需要添加一些代碼才能滾動。我不知道!如果您需要更多信息以幫助我將很樂意提供。我厭倦了試圖讓它工作。提前致謝。

ViewController.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 

ViewController.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 

回答

0

我張望了一下打併在答案中擺弄了一個例子,我得到了這個代碼:

scrollView.contentSize = CGSizeMake(320,2246); 

哪個工作!我花了好幾天的時間研究這個,這只是一小段代碼。我把它放到viewDidLoad中,它突然滾動。我也不得不打開「AutoLayout」。

0

您將需要設置ScrollViewContentSize,就像這樣:

[scrollView setContentSize:CGSizeMake(320, 500)]; 
+0

感謝您的回答。我已經試過了,但把它放在「 - (void)viewDidLoad」部分。那是放正確的地方嗎? – 2013-04-28 18:09:37

+0

是的,這是正確的地方。 – DRP 2013-04-28 18:21:12

+0

好吧,它不起作用。我對於發生了什麼問題感到非常困惑。不管怎麼說,還是要謝謝你。 – 2013-04-28 18:33:23

相關問題