2014-02-13 88 views
0
CGRect rectSearchLocationFrame=self.rectsearchLocation; 
CGRect rectSearchCityFrame = self.rectsearchCity; 

rectSearchLocationFrame.size.width += change *changeByMuch; 
rectSearchCityFrame.size.width -= change * changeByMuch; 
rectSearchCityFrame.origin.x +=change*changeByMuch; 
self.searchLocation.frame = rectSearchLocationFrame; 
self.searchCity.frame = rectSearchCityFrame; 

PO1(self.searchLocation.textField); 
PO1(self.searchCity.textField); 
//NSAssert(false, @"Hello"); 

我仔細看。 self.searchLocation的確有變化框架爲什麼更改UISearchBar的框架根本不起作用

(lldb) po self.searchLocation 
<BGSearchBar: 0x158e5130; baseClass = UISearchBar; frame = (0 38; 260 44); text = ''; opaque = NO; autoresize = W+BM; gestureRecognizers = <NSArray: 0x158d1ba0>; layer = <CALayer: 0x158e5220>> 

你看,框架?那裏的寬度是260,而不是160.它不應該在中間結束。

然而,這是截圖

enter image description here

如果我動畫的運動,似乎它實際上改變大小。然而,它慢慢迴歸。有些東西可以回到原來的大小。

我得到這個錯誤:

invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

+0

你在你的筆尖中使用了自動佈局嗎?試試self.searchbar.translatesAutoresizingMaskIntoConstraints =否如果是的話。 –

+0

嘗試記錄'rectSearchLocationFrame'而不是視圖幀請注意'frame'屬性是動畫的,所以它不必在改變後不久顯示當前的大小。 – Sulthan

回答

0

試試這個

[UIView beginAnimations:nil context:nil]; 

<duration of animation> 
<change frame of your search bar> 

[UIView commitAnimations]; 

[UIView 
    animateWithDuration:0.1 
    animations:^{ 

     <change frame of your search bar> 

    } 
    completion:^(BOOL finished) { 


    }]; 
0
-(void) setActiveSearchBar:(BGSearchBar *)activeSearchBar 
{ 

    _activeSearchBar=activeSearchBar; 
    AssertMainThread 
    if (activeSearchBar==self.searchLocation) 
    { 
     [self vChangeFrameBy:1]; 
    } 
    else if (activeSearchBar==self.searchCity) 
    { 
     [self vChangeFrameBy:-1]; 
    } 
    else if (activeSearchBar==self.searchBusiness) 
    { 
     [self vChangeFrameBy:0]; 
    } 
} 

我犯了一個愚蠢的錯誤

看看上面的代碼。有一個額外的;後最後別人的原代碼,如果

所以最後否則,如果是這樣的:

else if (activeSearchBar==self.searchBusiness); 
    { 
     [self vChangeFrameBy:0]; 
    } 

這意味着[自vChangeFrameBy:0];總是被稱爲不管是什麼:(

相關問題