Antialiasing edges of UIView after transformation using CALayer's transform

后端 未结 4 1061
别跟我提以往
别跟我提以往 2020-12-12 22:44

I have a UIView object that rotates using CALayer\'s transform:

// Create uiview object.
UIImageView *block = [[UIImageView alloc]          


        
4条回答
  •  半阙折子戏
    2020-12-12 23:38

    One way to do this is by placing the image inside another view that's 5 pixels bigger. The bigger view should have a transparent rasterized border that will smooth the edges of the UIImageView:

    view.layer.borderWidth = 3; 
    view.layer.borderColor = [UIColor clearColor].CGColor; 
    view.layer.shouldRasterize = YES; 
    view.layer.rasterizationScale = [[UIScreen mainScreen] scale];
    

    Then, place your UIImageView inside this parent view and center it (With 2.5 pixels around each edge).

    Finally, rotate the parent view instead of the image view.

    It works very well - you can also encapsulate the whole thing in class that creates the hierarchy.

提交回复
热议问题