2014-10-22 107 views
0

這裏是奇怪的事情, 我正在移動UIView位置的代碼,它在ios7中完美工作,但在ios8動畫重置動畫,即使我chaning任何標籤在控制器中的文本,這真的很適合我[UIView animateWithDuration動畫更改後更改標籤文本

if (!self.setTouch) { 
    [UIView animateWithDuration:kViewAnimateWithDuration 
    delay:kViewDelay 
    options:UIViewAnimationOptionCurveEaseInOut | 
    UIViewAnimationOptionAllowUserInteraction 
    animations:^{ 
     //Move frame or transform view 
     [self.sliderView setFrame:CGRectMake(self.sliderView.frame.origin.x,-205,self.sliderView.frame.size.width,249)]; 
     self.setTouch = YES; 
     // [self.containerView setFrame:CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y +171, width_b, height_b -171)]; 
    } completion:^(BOOL finished) { 
     self.setTouch = YES; 
    }]; 
} else { 
    [UIView animateWithDuration:kViewAnimateWithDuration 
    delay:kViewDelay 
    options:UIViewAnimationOptionCurveEaseInOut | 
    UIViewAnimationOptionAllowUserInteraction 
    animations:^{ 
     [self.sliderView setFrame:CGRectMake(self.sliderView.frame.origin.x,0.0f,self.sliderView.frame.size.width,249.0)]; 
     self.setTouch = NO; 
    } completion:^(BOOL finished) { 
     self.setTouch = NO; 
    }]; 
} 

這裏奇怪的是,這改變標籤文本代碼:

NSTimer *timer= [NSTimer scheduledTimerWithTimeInterval:5.0 target:self 
    selector:@selector(change_announcement:) userInfo:nil repeats:YES]; 

下面是實際的方法:

(IBAction)change_announcement:(id)sender { 
    if ([_announcements count] == 0) { 
     return; 
    } 

    AnnouncementDAO *ob = [_announcements objectAtIndex:_index]; 

    if(_isArabic){ 
     // [_label_announcementEn setHidden:YES]; 
     //[_label_announcementAr setHidden:NO]; 
     [_label_announcementAr setText:ob.announcementArabicTitle]; 
    } else{ 
     // [_label_announcementAr setHidden:YES]; 
     // [_label_announcementEn setHidden:NO]; 
     [_label_announcementEn setText:ob.announcementEngTitle]; 
    } 

    if (_index >= [_announcements count]-1) { 
     // NSLog(@"Make index 0"); 
     _index = -1; 
    } 
    _index ++; 
} 

當我的NSLog sliderView限制,我看到下面的輸出:

"<NSIBPrototypingLayoutConstraint:0x7b048740 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIView:0x7b04b6a0](LTR) (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b048710 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x7b04b6a0] (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b0486e0 'IB auto generated at build time for view with fixed frame' H:[UIView:0x7b04b6a0(768)]>", 
"<NSIBPrototypingLayoutConstraint:0x7b0486b0 'IB auto generated at build time for view with fixed frame' V:[UIView:0x7b04b6a0(25)]>", 
"<NSIBPrototypingLayoutConstraint:0x7b048680 'IB auto generated at build time for view with fixed frame' H:|-(348)-[UIButton:0x7b0e72b0](LTR) (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b048650 'IB auto generated at build time for view with fixed frame' V:|-(206)-[UIButton:0x7b0e72b0] (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b048620 'IB auto generated at build time for view with fixed frame' H:[UIButton:0x7b0e72b0(73)]>", 
"<NSIBPrototypingLayoutConstraint:0x7b0485f0 'IB auto generated at build time for view with fixed frame' V:[UIButton:0x7b0e72b0(22)]>", 
"<NSIBPrototypingLayoutConstraint:0x7b0485c0 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIView:0x7b04d690](LTR) (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b048590 'IB auto generated at build time for view with fixed frame' V:|-(25)-[UIView:0x7b04d690] (Names: '|':UIView:0x7b04b710)>", 
"<NSIBPrototypingLayoutConstraint:0x7b048560 'IB auto generated at build time for view with fixed frame' H:[UIView:0x7b04d690(768)]>", 
"<NSIBPrototypingLayoutConstraint:0x7b048530 'IB auto generated at build time for view with fixed frame' V:[UIView:0x7b04d690(181)]>" 
+0

什麼代碼看起來像你用來改變文本? – Flexicoder 2014-10-22 10:28:29

+0

編輯UILabel文本現在添加 – Ali 2014-10-22 10:37:42

回答

1

首先..改變你的代碼,這...

[UIView animateWithDuration:kViewAnimateWithDuration 
         delay:kViewDelay 
        options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction 
       animations:^{ 
        CGRect sliderFrame = self.sliderView.frame; 

        if (!self.setTouch) { 
         //Move frame or transform view 
         self.sliderView.frame = CGRectMake(CGRectGetMinX(sliderFrame), -205, CGRectGetWidth(sliderFrame), 249); 
         self.setTouch = YES; 
         //[self.containerView setFrame:CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y +171, width_b, height_b -171)]; 
        } else { 
         self.sliderView.frame = CGRectMake(CGRectGetMinX(sliderFrame), 0.0, CGRectGetWidth(sliderFrame), 249); 
         self.setTouch = NO; 
        } 
       } 
       completion:nil]; 

沒有必要讓它比它更復雜需要是。

第二......你在使用AutoLayout嗎?

編輯

您使用自動版式。這是它不工作的原因。使用AutoLayout時無法直接更改視圖的框架。

爲了動畫化視圖(或者只是移動它),你必須改變該視圖的約束條件。你不能觸摸框架或中心。它只是不起作用。

您需要獲取對要更改的約束的引用,並使用該引用來移動滑塊視圖。

我建議您看看Ray Wenderlich的網站。有一些很棒的AutoLayout教程用AutoLayout覆蓋動畫。

+0

不,我使用自動佈局只是在主UIScrollView上,設置手動位置在不同的其他視圖 – Ali 2014-10-22 10:35:46

+0

好的,爲我做這個...... NSLog(@「%@」,self.sliderView .constraints);''像'viewDidAppear'這樣的地方只是爲了檢查一些東西。讓我知道結果是什麼。 – Fogmeister 2014-10-22 10:39:46

+0

請檢查編輯的問題 – Ali 2014-10-22 10:45:45