2017-05-24 25 views
1

我想在點擊日曆按鈕時將日曆高度約束124更改爲零,我該怎麼做?我想使用按鈕語句,但我不能在客觀的c。謝謝。如何用按鈕更改高度約束?

@property (weak, nonatomic) IBOutlet UIBarButtonItem *calendarButton; 

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightOfCalendar;` 

- (IBAction)calendarAction:(id)sender { 

} 
+0

- (IBAction爲)calendarAction:(ID)發送方{ heightOfCalendar.constant = 0; } –

+0

不工作的人。 –

+0

給我同樣的錯誤。 –

回答

1

你需要設置不變的性質

heightOfCalendar.constant = requiredheight 
1

你可以這樣做,在每個水龍頭

- (IBAction)calendarAction:(id)sender { 
     sender.selected = !sender.selected; 
     heightOfCalendar.constant = (sender.selected)?0:124; 
} 
+0

發生錯誤,在對象類型'_strong id'上未找到Property'selected'。我該怎麼辦? –

1

改變大小有做這動畫將看起來不錯

(IBAction)calendarAction:(id)sender { 
[UIView animateWithDuration:0.5 
         animations:^{ 

          heightOfCalendar.constant =0; 
          [self.view layoutIfNeeded]; 

         }]; 
} 
1

寫這樣的代碼在你的IBAction爲:

- (IBAction)calendarAction:(id)sender { 
    self.heightOfCalendar.constant = 0; 
} 

另外,還要確保你有你的IBAction爲連接設置正確。

我看到一個`符號在下面的語句的末尾:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightOfCalendar;`