[英]DRAGGED uiview iOS
我在iOS故事板上使用SIZES CLASSES
。 我想在簡單按鈕操作的uiview中加載uitableview
。 我面臨的是第一次打開時從左向右拖動視圖。 單擊按鈕時,它在UIVIEW's
框架中顯示為正常。 我還給出了如圖所示的尾隨水平空間和前導水平空間,但是仍然無法避免在第一次加載時拖拽uitableview
。 UITABLEVIEW
從左向右拖動(似乎有一個前導空格,但沒有。我也提供了前導和尾隨空格,因此UIVIEW
應該使自己在屏幕的中央對齊。)
我在ViewDidLoad方法[self MYBUTTON];
調用[self MYBUTTON];
自動觸發按鈕並在UITABLEVIEW
中加載UIVIEW
。 但是我加載了拖動的UITABLE VIEW
但是當我單擊該按鈕時,它正常且很好地加載。
我要檢查什么,我要重點關注什么。 SIZES CLASSES
,約束UIVIEW
,或限制UITABLEVIEW
或我的編碼。 如何解決這個問題,以及我需要哪種特殊的解決方案來處理此自動觸發的UIVIEW
?
我的密碼:
- (void)viewDidLoad
{
[self MYBUTTON]; // auto triigger on first load
[self.MYBUTTON addTarget:self action:@selector(myB) forControlEvents:UIControlEventTouchUpInside];
}
-(void)myB{
[self unslelectallbuttons];
self.MYBUTTON.selected = YES;
for(UIView *subview in [self.contentView subviews]) {
[subview removeFromSuperview];
}
MYTABLEVIEW *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"mytable"];
vc.view.frame = self.contentView.bounds;
[vc willMoveToParentViewController:self];
[self.contentView addSubview:vc.view];
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];
}
我不確定訂單是否重要,但這對我有用。 如您所描述的,tableView應該就地顯示,沒有從側面動畫的證據。
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
[vc didMoveToParentViewController:self];
在我的應用程序中,我為懶惰實例化的tableView控制器保留了一個屬性:
- (BIBLESelectBookViewController *)selectBookViewController {
if (!_selectBookViewController) {
UIStoryboard *storyboard = self.storyboard;
_selectBookViewController = [storyboard instantiateViewControllerWithIdentifier:@"BibleKitSelectBookViewControllerID"];
_selectBookViewController.currentBook = self.currentBook;
}
return _selectBookViewController;
}
我猜您正在按不同的表騎車,具體取決於所按下的按鈕。 (我使用分段控件。)您可能希望轉換視圖控制器,而不是在沒有通知的情況下從容器中突然刪除它們。
這是我使用的循環方法:
- (void)cycleFromViewController:(UIViewController *)firstController toViewController:(UIViewController *)secondController animateInFromRight:(BOOL)fromRight {
// Disable segmented control interaction during the view controller transition
self.booksChaptersVersesSegmentedControl.userInteractionEnabled = NO;
[self addChildViewController:secondController];
[firstController willMoveToParentViewController:nil];
CGFloat offset = CGRectGetWidth(firstController.view.frame) * (fromRight ? 1 : -1);
CGRect frame = firstController.view.frame;
frame.origin.x += offset; // second controller animates in from right (left)
secondController.view.frame = frame;
[self transitionFromViewController:firstController
toViewController:secondController
duration:0.3
options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
secondController.view.frame = firstController.view.frame;
CGRect frame = firstController.view.frame;
frame.origin.x -= offset; // first controller animates out to left (right)
firstController.view.frame = frame;
[self setToolbarItems:secondController.toolbarItems animated:YES];
[self.navigationController setToolbarHidden:self.toolbarItems ? NO : YES animated:YES];
}
completion:^(BOOL __unused finished) {
[firstController removeFromParentViewController];
[secondController didMoveToParentViewController:self];
self.booksChaptersVersesSegmentedControl.userInteractionEnabled = YES;
}
];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.