Tôi đang cố gắng thêm thao tác vuốt để thay đổi chế độ xem thành ứng dụng tabbar của tôi. Giống như lượt xem trang.UIView Vuốt hoạt ảnh trượt nhanh
Cho đến nay giải pháp của tôi đang hoạt động nhưng tôi bị trục trặc trong khi vuốt, tôi cho rằng đó là view.frame (CGRectMake
) thay đổi gây ra những trục trặc màu đen nhưng tôi không hiểu tại sao nó xảy ra.
Điều này không xảy ra trong thiết bị không tốt như trình mô phỏng nhưng vẫn hiển thị và không mượt mà.
như vậy trong thư mục gốc của tôi tabbar
điều khiển (TabViewController : UITabBarController
)
#import <QuartzCore/QuartzCore.h>
#define XCTabViewDummyNSUintegerNOTargetVC 10
#define XCTabViewSwipeYAxisMax 40
#define XCTabViewSwipeXAxisMax 40
@interface XCTabViewController()
@property (nonatomic, strong) id<XCTabControlStrategy> tabStrategy;
@property double swipeRatio;
@property double toViewX;
@property double fromViewX;
@property UIView * fromView;
@property UIView * toView;
@end
sau đó
-(void)viewDidAppear:(BOOL)animated
{
XCDeviceType deviceType = [UIViewUtils currentDeviceType];
swipeRatio = 320;
switch (deviceType) {
case XCiPhone4:
swipeRatio = 320;
break;
case XCiPhone5:
swipeRatio = 320;
break;
case XCiPhone6:
swipeRatio = 375;
break;
case XCiPhone6Plus:
swipeRatio = 414;
break;
default:
swipeRatio = 320;
break;
}
// add pan recognizer to the view when initialized
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognized:)];
[panRecognizer setDelegate:(id)self];
[self.view addGestureRecognizer:panRecognizer]; // add to the view you want to detect swipe on
}
sau đó
-(void)panRecognized:(UIPanGestureRecognizer *)sender{
CGPoint distance = [sender translationInView: self.view];
if (sender.state == UIGestureRecognizerStateChanged) {
if (distance.x > XCTabViewSwipeXAxisMax && distance.y > -XCTabViewSwipeYAxisMax && distance.y < XCTabViewSwipeYAxisMax) { // right
[sender cancelsTouchesInView];
NSLog(@"user swiped right");
NSLog(@"swipe direction \n ---------------->"); //view on the left should be displayed
NSLog(@"distance.x %f", distance.x);
if (self.selectedIndex >= 1) {
NSUInteger targetVc = self.selectedIndex - 1;
// Get the views.
fromView = self.selectedViewController.view;
toView = [[self.viewControllers objectAtIndex:targetVc] view];
// Get the size of the view area.
CGRect viewSize = fromView.frame;
// Add the to view to the tab bar view.
[fromView.superview addSubview:toView];
// Position it off screen.
toView.frame = CGRectMake(-swipeRatio, viewSize.origin.y, swipeRatio, viewSize.size.height);
[UIView animateWithDuration:0 animations:^{
// Animate the views on and off the screen. This will appear to slide.
fromView.frame =CGRectMake(distance.x, viewSize.origin.y, swipeRatio, viewSize.size.height);
toView.frame =CGRectMake(-swipeRatio+distance.x, viewSize.origin.y, swipeRatio, viewSize.size.height);
toViewX = -swipeRatio+distance.x;
fromViewX = distance.x;
}];
}
}
}
Làm cách nào để làm cho hoạt ảnh này mượt mà hơn?
Ngoài việc vuốt mạnh, tôi nhận được cảnh báo bộ nhớ.